Add date to blog posts

This commit is contained in:
Jake Howard 2022-06-19 21:03:05 +01:00
parent 29673c365f
commit ce68aa7291
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 27 additions and 2 deletions

View file

@ -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),
),
]

View file

@ -2,6 +2,7 @@ from typing import Any
from django.db import models from django.db import models
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.utils import timezone
from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey from modelcluster.fields import ParentalKey
from taggit.models import ItemBase, TagBase from taggit.models import ItemBase, TagBase
@ -47,7 +48,10 @@ class BlogPostPage(BaseContentMixin, BasePage): # type: ignore[misc]
parent_page_types = [BlogListPage] parent_page_types = [BlogListPage]
tags = ClusterTaggableManager(through=TaggedBlog, blank=True) tags = ClusterTaggableManager(through=TaggedBlog, blank=True)
date = models.DateField(default=timezone.now)
content_panels = ( content_panels = (
BasePage.content_panels + BaseContentMixin.content_panels + [FieldPanel("tags")] BasePage.content_panels
+ BaseContentMixin.content_panels
+ [FieldPanel("date"), FieldPanel("tags")]
) )

View file

@ -15,7 +15,9 @@
<h2 class="subtitle">{{ page.subtitle }}</h2> <h2 class="subtitle">{{ page.subtitle }}</h2>
{% endif %} {% endif %}
<h3 class="is-size-6 content-details"> <h3 class="is-size-6 content-details">
<span title="2022-04-15"><i class="far fa-calendar-alt"></i>2022-04-15</span> {% if page.date %}
<span title="{{ page.date }}"><i class="far fa-calendar-alt"></i>{{ page.date|date:"Y-m-d" }}</span>
{% endif %}
<span><i class="far fa-clock"></i>4 minutes</span> <span><i class="far fa-clock"></i>4 minutes</span>
{% if page.tags.all %} {% if page.tags.all %}
<span class="is-family-code"><i class="fas fa-tags"></i>{% for tag in page.tags.all %}<a title="{{ tag.name }}">#{{ tag.slug }}</a>{% endfor %}</span> <span class="is-family-code"><i class="fas fa-tags"></i>{% for tag in page.tags.all %}<a title="{{ tag.name }}">#{{ tag.slug }}</a>{% endfor %}</span>