diff --git a/app/item/admin.py b/app/item/admin.py index 3d41227..cc06dd2 100644 --- a/app/item/admin.py +++ b/app/item/admin.py @@ -32,3 +32,9 @@ class CommentAdmin(admin.ModelAdmin): raw_id_fields = ['item', 'user'] admin.site.register(models.Comment, CommentAdmin) + + +class WeekAdmin(admin.ModelAdmin): + search_fields = ['monday'] + +admin.site.register(models.Week, WeekAdmin) diff --git a/app/item/migrations/0006_week.py b/app/item/migrations/0006_week.py new file mode 100644 index 0000000..ae39588 --- /dev/null +++ b/app/item/migrations/0006_week.py @@ -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="")), + ], + ), + ] diff --git a/app/item/models.py b/app/item/models.py index f114b38..c8c1772 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -173,3 +173,12 @@ class Comment(models.Model): data['published'] = self.is_published 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) diff --git a/app/item/views.py b/app/item/views.py index 27be4b0..87253b9 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -34,7 +34,12 @@ def format_week(week): fmt = '%b %d' a = a.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): @@ -80,6 +85,9 @@ def archive(request, year=None, month=None, day=None, week=None): context['weeks'] = get_weeks(archive) context['this_week'] = date.strftime('%Y-%m-%d') 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: week = int(week) year = int(year) diff --git a/app/templates/archive.html b/app/templates/archive.html index dccdff0..cfca179 100644 --- a/app/templates/archive.html +++ b/app/templates/archive.html @@ -4,12 +4,10 @@ {% endblock %} {% block content %}