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
PROMO_CHOICES = [("", "Sans promo")] + [
(r, r) for r in range(1980, date.today().year + 1)
]
def get_promo_choices():
return [("", "Sans promo")] + [(r, r) for r in range(1980, date.today().year + 1)]
class AccountForm(forms.ModelForm):
promo = forms.TypedChoiceField(
choices=PROMO_CHOICES,
choices=get_promo_choices,
coerce=int,
empty_value=None,
initial=default_promo(),
initial=default_promo,
required=False,
)