Utilise des callables pour les choix

This commit is contained in:
Tom Hubrecht 2021-07-01 10:29:14 +02:00
parent f70eacfc37
commit 2d677b2093

View file

@ -55,17 +55,16 @@ def default_promo():
return now.month <= 8 and now.year - 1 or now.year return now.month <= 8 and now.year - 1 or now.year
PROMO_CHOICES = [("", "Sans promo")] + [ def get_promo_choices():
(r, r) for r in range(1980, date.today().year + 1) return [("", "Sans promo")] + [(r, r) for r in range(1980, date.today().year + 1)]
]
class AccountForm(forms.ModelForm): class AccountForm(forms.ModelForm):
promo = forms.TypedChoiceField( promo = forms.TypedChoiceField(
choices=PROMO_CHOICES, choices=get_promo_choices,
coerce=int, coerce=int,
empty_value=None, empty_value=None,
initial=default_promo(), initial=default_promo,
required=False, required=False,
) )