khashashin
khashashin

Reputation: 1137

Wagtail ChoiceBlock error

Can you help me to convert following code so that will work for choiceblock in wagtail

YEAR_CHOICES = []
for r in range(1999, (datetime.now().year+1)):
    YEAR_CHOICES.append((r,r))

class Spieler(StructBlock):
    jahrgang = ChoiceBlock(_('year'), max_length=4, choices=YEAR_CHOICES, default=datetime.now().year)

at the moment I have the following error

  File "C:\Users\xakep\GitHub\treichle_cup\team_rooster\models.py", line 31, in <module>
    class Spieler(StructBlock):
  File "C:\Users\xakep\GitHub\treichle_cup\team_rooster\models.py", line 37, in Spieler
    jahrgang = ChoiceBlock(_('year'), max_length=4, choices=YEAR_CHOICES, default=datetime.now().year)
TypeError: __init__() got multiple values for argument 'choices'

Upvotes: 0

Views: 301

Answers (1)

gasman
gasman

Reputation: 25317

_('year') should be passed as label=_('year'):

jahrgang = ChoiceBlock(label=_('year'), max_length=4, choices=YEAR_CHOICES, default=datetime.now().year)

ChoiceBlock only accepts named arguments - if you leave out the name, it'll think that you're passing a choices value instead.

Upvotes: 1

Related Questions