创建自定义表单时,我的语法错误。错误发生在最后一行“self.fields ...”。有谁知道正确的语法?
class UpdateStateWithOptionsForm(forms.ModelForm):
class Meta:
model = State
def __init__(self, *args, **kwargs):
super(UpdateStateWithOptionsForm, self).__init__(*args, **kwargs)
self.fields['relevantoption']forms.ModelMultipleChoiceField(queryset=Option.objects.all(),required=True, widget=forms.CheckboxSelectMultiple)
答案 0 :(得分:2)
您缺少分配标志=
:
self.fields['relevantoption']forms.ModelMultipleChoiceField(queryset=Option.objects.all(),required=True, widget=forms.CheckboxSelectMultiple)
应该是:
self.fields['relevantoption'] = forms.ModelMultipleChoiceField(queryset=Option.objects.all(),required=True, widget=forms.CheckboxSelectMultiple)