Skip to content

Commit

Permalink
✨(admin) add certificate definition field into order admin change view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbpenrath committed Apr 1, 2022
1 parent 4174c40 commit f1ece51
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/backend/joanie/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<a href='{reverse('admin:core_certificatedefinition_change', args=(certificate_definition.id,), )}'>"
f"{str(certificate_definition)}"
"</a>"
)
)


@admin.register(models.Course)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f1ece51

Please sign in to comment.