自定义窗体中的语法错误

时间:2013-08-27 17:02:03

标签: django

创建自定义表单时,我的语法错误。错误发生在最后一行“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)

1 个答案:

答案 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)