From ce68aa729154708c92e848c981679fa6e2532bdc Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 19 Jun 2022 21:03:05 +0100 Subject: [PATCH] Add date to blog posts --- .../blog/migrations/0003_blogpostpage_date.py | 19 +++++++++++++++++++ website/blog/models.py | 6 +++++- website/common/templates/common/hero.html | 4 +++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 website/blog/migrations/0003_blogpostpage_date.py diff --git a/website/blog/migrations/0003_blogpostpage_date.py b/website/blog/migrations/0003_blogpostpage_date.py new file mode 100644 index 0000000..0308d49 --- /dev/null +++ b/website/blog/migrations/0003_blogpostpage_date.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.5 on 2022-06-19 19:57 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("blog", "0002_blogposttag_taggedblog_blogpostpage_tags"), + ] + + operations = [ + migrations.AddField( + model_name="blogpostpage", + name="date", + field=models.DateField(default=django.utils.timezone.now), + ), + ] diff --git a/website/blog/models.py b/website/blog/models.py index 96fe202..1be8a3c 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -2,6 +2,7 @@ from typing import Any from django.db import models from django.http.request import HttpRequest +from django.utils import timezone from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey from taggit.models import ItemBase, TagBase @@ -47,7 +48,10 @@ class BlogPostPage(BaseContentMixin, BasePage): # type: ignore[misc] parent_page_types = [BlogListPage] tags = ClusterTaggableManager(through=TaggedBlog, blank=True) + date = models.DateField(default=timezone.now) content_panels = ( - BasePage.content_panels + BaseContentMixin.content_panels + [FieldPanel("tags")] + BasePage.content_panels + + BaseContentMixin.content_panels + + [FieldPanel("date"), FieldPanel("tags")] ) diff --git a/website/common/templates/common/hero.html b/website/common/templates/common/hero.html index c9af2d1..a69bbba 100644 --- a/website/common/templates/common/hero.html +++ b/website/common/templates/common/hero.html @@ -15,7 +15,9 @@

{{ page.subtitle }}

{% endif %}

- 2022-04-15 + {% if page.date %} + {{ page.date|date:"Y-m-d" }} + {% endif %} 4 minutes {% if page.tags.all %} {% for tag in page.tags.all %}#{{ tag.slug }}{% endfor %}