开发者

Django Form won't submit error says Select a Valid Choice ____ is not one of the available choices

开发者 https://www.devze.com 2023-03-07 07:26 出处:网络
I built a form in django and I\'m having trouble debugging my Tours Choices.It is a ChoiceField and I use the CheckboxMultipleSelect Widget.I don\'t know what I\'m doing wrong to get the error in the

I built a form in django and I'm having trouble debugging my Tours Choices. It is a ChoiceField and I use the CheckboxMultipleSelect Widget. I don't know what I'm doing wrong to get the error in the scree开发者_JAVA技巧nshot below. Any thoughts? Do I need to facilitate more information? I'm a django newbie.

Picture of the Form Error


A form.ChoiceField lets you input exactly one choice for a form (out of a selection of several choices). If you saved it to a database in a model there would be one value stored in the database. Your CheckboxMultipleSelect widget is for a form.MultipleChoiceField where you can input multiple values. So change your ChoiceField to a MultipleChoiceField in your form and you should be fine. If you save this data to a model, that model would have to be an appropriate field, like a ManyToManyField if they are Foreign Keys.

0

精彩评论

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