Add admin link to article
This commit is contained in:
parent
bd55cc0e33
commit
9a50fa408f
4 changed files with 19 additions and 2 deletions
|
@ -2,7 +2,9 @@ import re
|
||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +34,16 @@ class Article(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
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):
|
def get_abstract(self):
|
||||||
html = self.get_formatted_content()
|
html = self.get_formatted_content()
|
||||||
return html.split("<!--more-->")[0]
|
return html.split("<!--more-->")[0]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<article>
|
<article>
|
||||||
<h1>{{ article.title }}{% if article.status != article.PUBLISHED %} ({{ article.status }}){% endif %}</h1>
|
<h1>{{ article.title }}{% if article.status != article.PUBLISHED %} ({{ article.status }}){% endif %}</h1>
|
||||||
{% include "articles/date_snippet.html" %}
|
{% include "articles/metadata_snippet.html" %}
|
||||||
<div>
|
<div>
|
||||||
{{ article.get_formatted_content|safe }}
|
{{ article.get_formatted_content|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
{% for article in articles %}
|
{% for article in articles %}
|
||||||
<article>
|
<article>
|
||||||
<h2><a href="{% url 'article-detail' pk=article.pk %}">{{ article.title }}</a></h2>
|
<h2><a href="{% url 'article-detail' pk=article.pk %}">{{ article.title }}</a></h2>
|
||||||
{% include "articles/date_snippet.html" %}
|
{% include "articles/metadata_snippet.html" %}
|
||||||
<p>{{ article.get_abstract|safe }}</p>
|
<p>{{ article.get_abstract|safe }}</p>
|
||||||
<p><a href="{% url 'article-detail' pk=article.pk %}">Read more</a></p>
|
<p><a href="{% url 'article-detail' pk=article.pk %}">Read more</a></p>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<p>
|
||||||
|
<a href="{{ article.get_admin_url }}">Admin</a>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
<p class="date">
|
<p class="date">
|
||||||
{% if article.published_at %}
|
{% if article.published_at %}
|
||||||
{{ article.published_at|date }}
|
{{ article.published_at|date }}
|
Reference in a new issue