0
創建自定義表單時,我在語法中收到錯誤。錯誤發生在最後一行「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)
這就是它!它看起來像我也可以添加一個'。'而不是'='。兩者都不會提出錯誤。 – nlr25
但是隻有其中一個會分配一個值! –