diff --git a/scipost_django/colleges/admin.py b/scipost_django/colleges/admin.py index 316320cdbf4c4aa8df393a863e65c5b669e0e1b6..26fb0ab1b581a4849be097575fa9d1b5061fbc33 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