From fb71dfaa40fe3fa3c15f656fb55a2f0fb30f3ec9 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 25 Jul 2023 11:28:07 +0300 Subject: [PATCH] filter voting fellows in nomination vote admin --- scipost_django/colleges/admin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scipost_django/colleges/admin.py b/scipost_django/colleges/admin.py index 316320cdb..26fb0ab1b 100644 --- a/scipost_django/colleges/admin.py +++ b/scipost_django/colleges/admin.py @@ -116,6 +116,14 @@ class FellowshipNominationVoteInline(admin.TabularInline): model = FellowshipNominationVote extra = 0 + # Filter "fellow" field to only those who are eligible to vote + def formfield_for_foreignkey(self, db_field, request, **kwargs): + if db_field.name == "fellow": + kwargs["queryset"] = FellowshipNominationVotingRound.objects.get( + pk=request.resolver_match.kwargs["object_id"] + ).eligible_to_vote.all() + return super().formfield_for_foreignkey(db_field, request, **kwargs) + class FellowshipNominationVotingRoundAdmin(admin.ModelAdmin): model = FellowshipNominationVotingRound -- GitLab