Add data to articles admin

This commit is contained in:
Gabriel Augendre 2020-12-28 08:42:30 +01:00
parent 91b99435bf
commit c2c92dc62d
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 23 additions and 4 deletions

View file

@ -21,9 +21,18 @@ class ArticleAdmin(admin.ModelAdmin):
"published_at",
"updated_at",
"views_count",
"has_code",
"is_home",
"has_custom_css",
"read_time",
]
list_display_links = ["title"]
list_filter = ["status"]
list_filter = [
"status",
"has_code",
"status",
"is_home",
]
date_hierarchy = "created_at"
fieldsets = [
(
@ -34,8 +43,8 @@ class ArticleAdmin(admin.ModelAdmin):
("author", "keywords"),
("status", "published_at"),
("created_at", "updated_at"),
"views_count",
"has_code",
("views_count", "read_time"),
("has_code", "has_custom_css"),
]
},
),
@ -57,6 +66,8 @@ class ArticleAdmin(admin.ModelAdmin):
"views_count",
"status",
"published_at",
"read_time",
"has_custom_css",
]
prepopulated_fields = {"slug": ("title",)}
change_form_template = "articles/article_change_form.html"
@ -113,3 +124,11 @@ class ArticleAdmin(admin.ModelAdmin):
messages.success(request, "Item has been unpublished")
return redirect(".")
return super().response_change(request, obj)
def read_time(self, instance: Article):
return f"{instance.get_read_time()} min"
def has_custom_css(self, instance: Article):
return bool(instance.custom_css)
has_custom_css.boolean = True

View file

@ -1,5 +1,5 @@
<p>
Published on {% include "articles/snippets/datetime.html" %}
&centerdot; {{ article.get_read_time }} minutes read
&centerdot; {{ article.get_read_time }} min read
{% include "articles/snippets/admin_link.html" %}
</p>