From: Patrick Canterino Date: Sat, 14 May 2022 15:46:03 +0000 (+0200) Subject: Show publication date when rendering a note X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/218a404a6467fc7acab06efd5f1049acbc174cf2 Show publication date when rendering a note Show creation date if publication date is not available --- diff --git a/notes/models.py b/notes/models.py index 5541224..f5ab091 100644 --- a/notes/models.py +++ b/notes/models.py @@ -64,6 +64,12 @@ class Note(models.Model): def is_published(self): return self.status == 1 + def publication_date(self): + if self.published_at is None: + return self.created_at + else: + return self.published_at + @receiver(pre_save, sender=Note) def note_pre_save(sender, instance, **kwargs): if instance.pk is None: diff --git a/notes/templates/note.html b/notes/templates/note.html index b2b7519..d965325 100644 --- a/notes/templates/note.html +++ b/notes/templates/note.html @@ -3,5 +3,5 @@

{{ note.title }}

{% if note.is_draft %}

Status: Draft

{% endif %}
{{ note.content|markdown|safe }}
-

Published on {{ note.created_at|date:"Y-m-d, H:i" }}

+

Published on {{ note.publication_date|date:"Y-m-d, H:i" }}

\ No newline at end of file