From aa61d02ecac472440fd46d4456fd0afe4985b443 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 2 Mar 2023 15:39:09 +0100 Subject: [PATCH] Cleanup submit row for articles --- src/articles/admin.py | 21 +++++++++++++++++++ .../admin/articles/article/submit_line.html | 12 ++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/articles/admin.py b/src/articles/admin.py index 4306143..e41b990 100644 --- a/src/articles/admin.py +++ b/src/articles/admin.py @@ -142,6 +142,27 @@ class ArticleAdmin(admin.ModelAdmin): return redirect(".") return super().response_change(request, obj) + def change_view( + self, + request: WSGIRequest, + object_id: int, + form_url: str = "", + extra_context: dict | None = None, + ) -> HttpResponse: + extra_context = extra_context or {} + extra_context["show_save_and_add_another"] = False + return super().change_view(request, object_id, form_url, extra_context) + + def add_view( + self, + request: WSGIRequest, + form_url: str = "", + extra_context: dict | None = None, + ) -> HttpResponse: + extra_context = extra_context or {} + extra_context["show_save_and_add_another"] = False + return super().add_view(request, form_url, extra_context) + def read_time(self, instance: Article) -> str: return f"{instance.get_read_time()} min" diff --git a/src/articles/templates/admin/articles/article/submit_line.html b/src/articles/templates/admin/articles/article/submit_line.html index 18eb215..16241ce 100644 --- a/src/articles/templates/admin/articles/article/submit_line.html +++ b/src/articles/templates/admin/articles/article/submit_line.html @@ -2,11 +2,13 @@ {% load static %} {% block submit-row %} {{ block.super }} - {% if original.status != original.PUBLISHED %} - - {% elif original.status != original.DRAFT %} - - {% endif %} + {% if original %}