From f1ece5162cc354662ab0254568f8c42dc352c3f3 Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Fri, 1 Apr 2022 16:13:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(admin)=20add=20certificate=20definiti?= =?UTF-8?q?on=20field=20into=20order=20admin=20change=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On certificate admin change view, we add a custom field to display the certificate definition which the certificate relies on. In order admin change, we also display the certificate if there is. --- src/backend/joanie/core/admin.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/joanie/core/admin.py b/src/backend/joanie/core/admin.py index 5b63bdc311..cd0dab43b1 100644 --- a/src/backend/joanie/core/admin.py +++ b/src/backend/joanie/core/admin.py @@ -55,6 +55,19 @@ class CertificateAdmin(admin.ModelAdmin): """Admin class for the Certificate model""" list_display = ("order", "issued_on") + readonly_fields = ("order", "issued_on", "certificate_definition") + + def certificate_definition(self, obj): # pylint: disable=no-self-use + """Retrieve the certification definition from the related order.""" + certificate_definition = obj.order.product.certificate_definition + + return format_html( + ( + f"" + f"{str(certificate_definition)}" + "" + ) + ) @admin.register(models.Course) @@ -260,7 +273,7 @@ class OrderAdmin(DjangoObjectActions, admin.ModelAdmin): """Admin class for the Order model""" list_display = ("uid", "owner", "product", "state") - readonly_fields = ("total", "invoice") + readonly_fields = ("total", "invoice", "certificate") change_actions = (ACTION_NAME_GENERATE_CERTIFICATES,) actions = (ACTION_NAME_CANCEL, ACTION_NAME_GENERATE_CERTIFICATES)