]> git.p6c8.net - pcdenotes.git/commitdiff
Show publication date when rendering a note
authorPatrick Canterino <patrick@patrick-canterino.de>
Sat, 14 May 2022 15:46:03 +0000 (17:46 +0200)
committerPatrick Canterino <patrick@patrick-canterino.de>
Sat, 14 May 2022 15:46:03 +0000 (17:46 +0200)
Show creation date if publication date is not available

notes/models.py
notes/templates/note.html

index 5541224bbc1f5a39fbd38aca07dd9e2eb434cf81..f5ab091af915b954d113b7e0fdebd3f58b9642d0 100644 (file)
@@ -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:
index b2b7519ebbed305b78603c975aa6d8cce17b7fd7..d965325cc44e4670ba3389a09a3393e8825b04bf 100644 (file)
@@ -3,5 +3,5 @@
     <h2><a href="{{ note.get_absolute_url }}"{% if note.is_draft %} class="text-muted"{% endif %}>{{ note.title }}</a></h2>
     {% if note.is_draft %}<p class="fw-bold">Status: Draft</p>{% endif %}
     <div>{{ note.content|markdown|safe }}</div>
-    <p class="publication-date">Published on {{ note.created_at|date:"Y-m-d, H:i" }}</p>
+    <p class="publication-date">Published on {{ note.publication_date|date:"Y-m-d, H:i" }}</p>
 </article>
\ No newline at end of file

patrick-canterino.de