我有覆盖清洁方法的问题。 在ModelAdmin中,我设置了自己的清理函数,
form = MyModelAdminForm
我不知道怎么称它为超级方法, 此时有人没有填写其他请求的字段 出现黄色屏幕
class MyModelAdminForm(forms.ModelForm):
class Meta:
model = MyModel
fields = '__all__'
def clean(self):
if (myCond):
raise forms.ValidationError("Message")
答案 0 :(得分:0)
official docs中详细记录了您要实现的目标。
class MyModelAdminForm(forms.ModelForm):
class Meta:
model = MyModel
fields = '__all__'
def clean(self):
# get cleaned data first
cleaned_data = super(MyModelAdminForm, self).clean() # for python 2
cleaned_data = super().clean() # for python 3
if myCond:
raise forms.ValidationError("Message")