From 6a4d1505f2485de027728e0776ac96ea85fe1154 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Tue, 4 Jun 2024 17:41:11 +0200 Subject: [PATCH] dynamic update college in nominations search --- scipost_django/colleges/forms.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scipost_django/colleges/forms.py b/scipost_django/colleges/forms.py index cbe62e424..9609efdca 100644 --- a/scipost_django/colleges/forms.py +++ b/scipost_django/colleges/forms.py @@ -574,17 +574,9 @@ class FellowshipNominationForm(forms.ModelForm): class FellowshipNominationSearchForm(forms.Form): - all_nominations = FellowshipNomination.objects.all() - nomination_colleges = all_nominations.values_list("college", flat=True).distinct() - nominee = forms.CharField(max_length=100, required=False, label="Nominee") - college = forms.MultipleChoiceField( - choices=College.objects.filter(id__in=nomination_colleges) - .order_by("name") - .values_list("id", "name"), - required=False, - ) + college = forms.MultipleChoiceField(required=False) decision = forms.ChoiceField( choices=[("", "Any"), ("pending", "Pending")] @@ -649,6 +641,13 @@ class FellowshipNominationSearchForm(forms.Form): self.session_key = kwargs.pop("session_key", None) super().__init__(*args, **kwargs) + self.fields["college"].choices = ( + FellowshipNomination.objects.all() + .values_list("college__id", "college__name") + .order_by("college__name") + .distinct() + ) + # Set the initial values of the form fields from the session data if self.session_key: session = SessionStore(session_key=self.session_key) -- GitLab