1๐
โ
Add a clean()
method to your model where you validate all the fields you need to validate and raise ValidationError
if something is wrong.
class users(models.Model):
...
def clean(self):
if not is_valid_surname(self.surname):
raise ValidationError({'surname': _('Invalid surname.')})
...
The docs are here.
๐คC14L
Source:stackexchange.com