Is this addition of a validator acceptable?
from django.core.validators import EmailValidator
class User(AbstractUser):
country = models.CharField(max_length=120, validators=validators['user']['country'])
city = models.CharField(max_length=120)
street_name = models.CharField(max_length=120)
postcode = models.CharField(max_length=20)
additional_address_details = models.TextField(blank=True, null=True)
phone_number = models.CharField(max_length=20)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
if update_fields is not None:
self.full_clean(exclude=update_fields)
else:
self.full_clean()
super().save(force_insert=force_insert, force_update=force_update,
using=using, update_fields=update_fields,)
User.email.validators = EmailValidator
UPD: I also wonder if django controls such restrictions as max_length=20 or leaves it to the database? If the second option, then as soon as the database returns an error, what python exception will be called? I didn’t find any information about this in the documentation (maybe I didn’t look hard enough).