week titles
This commit is contained in:
parent
92f21cc859
commit
bd6f03491c
5 changed files with 57 additions and 6 deletions
|
@ -32,3 +32,9 @@ class CommentAdmin(admin.ModelAdmin):
|
||||||
raw_id_fields = ['item', 'user']
|
raw_id_fields = ['item', 'user']
|
||||||
|
|
||||||
admin.site.register(models.Comment, CommentAdmin)
|
admin.site.register(models.Comment, CommentAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
class WeekAdmin(admin.ModelAdmin):
|
||||||
|
search_fields = ['monday']
|
||||||
|
|
||||||
|
admin.site.register(models.Week, WeekAdmin)
|
||||||
|
|
30
app/item/migrations/0006_week.py
Normal file
30
app/item/migrations/0006_week.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 4.2.3 on 2023-08-31 17:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("item", "0005_alter_comment_email_alter_comment_name_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Week",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("created", models.DateTimeField(auto_now_add=True)),
|
||||||
|
("modified", models.DateTimeField(auto_now=True)),
|
||||||
|
("monday", models.DateField(unique=True)),
|
||||||
|
("title", models.TextField(default="")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -173,3 +173,12 @@ class Comment(models.Model):
|
||||||
data['published'] = self.is_published
|
data['published'] = self.is_published
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class Week(models.Model):
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
monday = models.DateField(unique=True)
|
||||||
|
title = models.CharField(max_length=2048)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%s (%s)" % (self.title, self.monday)
|
||||||
|
|
|
@ -34,7 +34,12 @@ def format_week(week):
|
||||||
fmt = '%b %d'
|
fmt = '%b %d'
|
||||||
a = a.strftime(fmt)
|
a = a.strftime(fmt)
|
||||||
b = b.strftime(fmt)
|
b = b.strftime(fmt)
|
||||||
return '%s - %s' % (a, b)
|
extra = models.Week.objects.filter(monday=week).first()
|
||||||
|
if extra:
|
||||||
|
extra = ': ' + extra.title
|
||||||
|
else:
|
||||||
|
extra = ''
|
||||||
|
return '%s - %s%s' % (a, b, extra)
|
||||||
|
|
||||||
|
|
||||||
def get_weeks(archive):
|
def get_weeks(archive):
|
||||||
|
@ -80,6 +85,9 @@ def archive(request, year=None, month=None, day=None, week=None):
|
||||||
context['weeks'] = get_weeks(archive)
|
context['weeks'] = get_weeks(archive)
|
||||||
context['this_week'] = date.strftime('%Y-%m-%d')
|
context['this_week'] = date.strftime('%Y-%m-%d')
|
||||||
context['this_year'] = date.strftime('%Y')
|
context['this_year'] = date.strftime('%Y')
|
||||||
|
extra = models.Week.objects.filter(monday=context['this_week']).first()
|
||||||
|
if extra:
|
||||||
|
context['week_title'] = extra.title
|
||||||
elif week:
|
elif week:
|
||||||
week = int(week)
|
week = int(week)
|
||||||
year = int(year)
|
year = int(year)
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="index archive">
|
<div class="index archive">
|
||||||
|
{% if week_title %}
|
||||||
|
<h2 class="week">{{ week_title }}</h2>
|
||||||
|
{% endif %}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
{% ifchanged item.week %}
|
|
||||||
{% comment %}
|
|
||||||
<h2 class="week">{{ item.year }} week {{ item.week }}</h2>
|
|
||||||
{% endcomment %}
|
|
||||||
{% endifchanged %}
|
|
||||||
{% include "listitem.html" with item=item %}
|
{% include "listitem.html" with item=item %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if archive %}
|
{% if archive %}
|
||||||
|
|
Loading…
Reference in a new issue