From c2c92dc62d6c3d29b835e1fd635bd7e036f2f4b0 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 28 Dec 2020 08:42:30 +0100 Subject: [PATCH] Add data to articles admin --- articles/admin.py | 25 ++++++++++++++++--- .../templates/articles/snippets/metadata.html | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/articles/admin.py b/articles/admin.py index df3b844..bad4832 100644 --- a/articles/admin.py +++ b/articles/admin.py @@ -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 diff --git a/articles/templates/articles/snippets/metadata.html b/articles/templates/articles/snippets/metadata.html index 42ffac5..83e0239 100644 --- a/articles/templates/articles/snippets/metadata.html +++ b/articles/templates/articles/snippets/metadata.html @@ -1,5 +1,5 @@

Published on {% include "articles/snippets/datetime.html" %} - · {{ article.get_read_time }} minutes read + · {{ article.get_read_time }} min read {% include "articles/snippets/admin_link.html" %}