2👍
✅
According to This Docs for validating objects:
You can clean_fields(exclude=None)
which will validate all fields in model except the fields in exclude
.
From This doc:
Note that validators will not be run automatically when you save a
model, but if you are using a ModelForm, it will run your validators
on any fields that are included in your form.
More information about validating here.
EDIT
For field specific errors, clean_<field>()
can be used in forms
. Example:
terms_accepted= forms.BooleanField()
-------
-------
def clean_terms_accepted(self):
data = self.cleaned_data
if data['terms_accepted'] is not None:
return True
else:
msg="Durp!"
self._errors["terms_accepted"] = self.error_class([msg])
return False
Source:stackexchange.com