class YourModelForm(ModelForm):
def clean_field_name(self):
data = self.cleaned_data['field_name']
if not data: # 如果data不满足满足条件
raise forms.ValidationError('data is invalid')
return data
class Meta:
model = YourModel
fields = '__all__'
class YourModelAdmin(models.ModelAdmin):
form = YourModelForm