我正在尝试在我的应用程序中使用复选框,但 Django 表单验证告诉我输入无效,无论检查了哪些复选框。
在模型中:
AV_CHOICES = (
('PC', 'PC Laptop ($150)'),
('32', '32" LCD Monitor ($150)'),
('40', '40" LCD Monitor ($200)'),
)
Optional_AV_Requests = models.TextField(blank=True, choices=AV_CHOICES)
在forms.py
class Fair_Logistical_Data1Form(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(Fair_Logistical_Data1Form, self).__init__(*args, **kwargs)
self.fields['Optional_AV_Requests'] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,choices=self.fields['Optional_AV_Requests'].choices)
无论我选择哪个复选框,我都会收到一个内联错误,说“u'PC' is not a valid selection”之类的内容。有任何想法吗?