diff --git a/fet2020/posts/forms.py b/fet2020/posts/forms.py index 4ab26c93..143b6a4f 100644 --- a/fet2020/posts/forms.py +++ b/fet2020/posts/forms.py @@ -168,15 +168,20 @@ class PostSearchForm(forms.Form): year_choices = [('', _('Alle'))] month_choices = [('', _('Alle'))] + list(MONTHS.items()) - try: - first_post = Post.objects.get_queryset().last() - - if first_post: - year_of_first_post = first_post.public_date.year - years = range(year_of_first_post, timezone.now().date().year + 1) - year_choices += [(i, i) for i in years] - except: - pass - year = forms.ChoiceField(label="Jahr", choices=year_choices, required=False) month = forms.ChoiceField(label="Monat", choices=month_choices, required=False) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) # to get the self.fields set + + try: + first_post = Post.objects.get_queryset().last() + + if first_post: + year_of_first_post = first_post.public_date.year + years = range(year_of_first_post, timezone.now().date().year + 1) + year_choices = [('', _('Alle'))] + [(i, i) for i in years] + self.fields['year'].choices = year_choices + + except: + pass