Add date to blog posts
This commit is contained in:
parent
29673c365f
commit
ce68aa7291
3 changed files with 27 additions and 2 deletions
19
website/blog/migrations/0003_blogpostpage_date.py
Normal file
19
website/blog/migrations/0003_blogpostpage_date.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -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")]
|
||||
)
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
<h2 class="subtitle">{{ page.subtitle }}</h2>
|
||||
{% endif %}
|
||||
<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>
|
||||
{% 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>
|
||||
|
|
Loading…
Reference in a new issue