开发者

My model field gives me Value u'0' is not a valid choice error?

FOOBAR = (
    (0, 'foo'),
    (1, 'bar'),
)

class开发者_StackOverflow社区 Foobaz(models.Model):
    type = models.CharField(max_length=1, choices=FOOBAR, \
                                       verbose_name=_('foobar type'))

class FoobazForm(forms.ModelForm):
    class Meta:
    model = Foobaz
        fields = ('type')

In views foo_form = FoobazForm(request.POST) When I do foo_form.is_valid() It gives me validation error u'0' is not a valid choice. Where I am doing something wrong?


All I know about django is that it is a candidate for least euphonous package name of the decade, so this is a guess:

Users key in characters, not integers, so you should use:

FOOBAR = (
    ('0', 'foo'),
    ('1', 'bar'),
    )

Update Google is our friend: Here's some seemingly relevant documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜