From 55eaac955150d00892767d663141a6d5e2fff99b Mon Sep 17 00:00:00 2001 From: Virginia Dooley Date: Mon, 25 Sep 2023 12:16:01 +0100 Subject: [PATCH] Add Membership to Person in admin --- ynr/apps/people/admin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ynr/apps/people/admin.py b/ynr/apps/people/admin.py index 73cfe4c58..6a9740a0a 100644 --- a/ynr/apps/people/admin.py +++ b/ynr/apps/people/admin.py @@ -44,7 +44,17 @@ def post(self, request, *args, **kwargs): class MembershipInline(admin.StackedInline): extra = 0 + can_delete = False model = Membership + fields = ("party", "get_ballot", "deselected") + readonly_fields = ("party", "get_ballot") + + @admin.display(description="Ballot") + def get_ballot(self, obj): + return obj.ballot.ballot_paper_id + + def has_add_permission(self, request, obj=None): + return False class PersonImageInlineForm(forms.ModelForm): @@ -104,7 +114,7 @@ class PersonAdmin(admin.ModelAdmin): "image_preview", "image_filetype", ) - inlines = [PersonImageInline] + inlines = [PersonImageInline, MembershipInline] def image_preview(self, obj): person = Person.objects.get(pk=obj.pk)