diff --git a/articles/models.py b/articles/models.py index d7ae964..8dcf576 100644 --- a/articles/models.py +++ b/articles/models.py @@ -2,7 +2,9 @@ import re import markdown from django.contrib.auth.models import AbstractUser +from django.contrib.contenttypes.models import ContentType from django.db import models +from django.urls import reverse from django.utils import timezone @@ -32,6 +34,16 @@ class Article(models.Model): def __str__(self): return self.title + def get_admin_url(self): + content_type = ContentType.objects.get_for_model(self.__class__) + return reverse( + "admin:%s_%s_change" % (content_type.app_label, content_type.model), + args=(self.id,), + ) + + def get_absolute_url(self): + return reverse("article-detail", kwargs={"pk": self.pk}) + def get_abstract(self): html = self.get_formatted_content() return html.split("")[0] diff --git a/articles/templates/articles/article_detail.html b/articles/templates/articles/article_detail.html index a6f3ad7..c8cbb26 100644 --- a/articles/templates/articles/article_detail.html +++ b/articles/templates/articles/article_detail.html @@ -3,7 +3,7 @@ {% block content %}

{{ article.title }}{% if article.status != article.PUBLISHED %} ({{ article.status }}){% endif %}

- {% include "articles/date_snippet.html" %} + {% include "articles/metadata_snippet.html" %}
{{ article.get_formatted_content|safe }}
diff --git a/articles/templates/articles/article_list.html b/articles/templates/articles/article_list.html index 2468802..221b55b 100644 --- a/articles/templates/articles/article_list.html +++ b/articles/templates/articles/article_list.html @@ -5,7 +5,7 @@ {% for article in articles %}

{{ article.title }}

- {% include "articles/date_snippet.html" %} + {% include "articles/metadata_snippet.html" %}

{{ article.get_abstract|safe }}

Read more

diff --git a/articles/templates/articles/date_snippet.html b/articles/templates/articles/metadata_snippet.html similarity index 58% rename from articles/templates/articles/date_snippet.html rename to articles/templates/articles/metadata_snippet.html index 75d2c5c..5329d6a 100644 --- a/articles/templates/articles/date_snippet.html +++ b/articles/templates/articles/metadata_snippet.html @@ -1,3 +1,8 @@ +{% if user.is_authenticated %} +

+ Admin +

+{% endif %}

{% if article.published_at %} {{ article.published_at|date }}