class MyModel(models.Model):
foo = models.BooleanField()
# Wrong! Don't do this!
def clean_fields(self, exclude=None): # 指定某些字段排除验证
# Bah! Forgetting to pass exclude defaults it to None!
super(MyModel, self).clean_fields()
if not self.foo:
raise ValidationError('Ah fooey.')
# Correct! Do it this way!
def clean_fields(self, exclude=None):
# That's better! Let's take a coffee break. I'm tired.
super(MyModel, self).clean_fields(exclude)
if not self.foo:
raise ValidationError('Ah fooey.')
标签:ValidationError,fields,MyModel,clean,exclude,self
From: https://www.cnblogs.com/coilan/p/16836417.html