Wagtail ChoiceBlock错误

时间:2018-02-05 10:32:42

标签: wagtail

您能否帮我转换以下代码,以便适用于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)

目前我有以下错误

  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'

1 个答案:

答案 0 :(得分:1)

_('year')应作为label=_('year')传递:

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

ChoiceBlock只接受命名参数 - 如果省略名称,它会认为你传递的是choices值。