fix choices didn't updated.
This commit is contained in:
@@ -168,15 +168,20 @@ class PostSearchForm(forms.Form):
|
|||||||
year_choices = [('', _('Alle'))]
|
year_choices = [('', _('Alle'))]
|
||||||
month_choices = [('', _('Alle'))] + list(MONTHS.items())
|
month_choices = [('', _('Alle'))] + list(MONTHS.items())
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
first_post = Post.objects.get_queryset().last()
|
first_post = Post.objects.get_queryset().last()
|
||||||
|
|
||||||
if first_post:
|
if first_post:
|
||||||
year_of_first_post = first_post.public_date.year
|
year_of_first_post = first_post.public_date.year
|
||||||
years = range(year_of_first_post, timezone.now().date().year + 1)
|
years = range(year_of_first_post, timezone.now().date().year + 1)
|
||||||
year_choices += [(i, i) for i in years]
|
year_choices = [('', _('Alle'))] + [(i, i) for i in years]
|
||||||
|
self.fields['year'].choices = year_choices
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
year = forms.ChoiceField(label="Jahr", choices=year_choices, required=False)
|
|
||||||
month = forms.ChoiceField(label="Monat", choices=month_choices, required=False)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user