From 218a404a6467fc7acab06efd5f1049acbc174cf2 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sat, 14 May 2022 17:46:03 +0200 Subject: [PATCH 1/1] Show publication date when rendering a note Show creation date if publication date is not available --- notes/models.py | 6 ++++++ notes/templates/note.html | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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 -- 2.34.1