I am using the AbstractUser model to create a custom auth model.
The problem is that i was unable to override the default form field validators for the username fie
You can explicitly define a field on the form. That way, you have full control over the field, including its validators:
class RegularUserForm(forms.ModelForm):
username = forms.CharField(max_length=30)
class Meta:
model = User
Thankfully i found the solution, i was overriding the validators in the forms but not the ones in the models (also did the opposite) so i had to do this:
from utils import validate_username
class RegularUserForm(forms.ModelForm):
username = forms.CharField(max_length=50, validators=[validate_username])
and
class RegularUser(AbstractUser):
def __init__(self, *args, **kwargs):
super(RegularUser, self).__init__(*args, **kwargs)
self._meta.get_field('username').validators = [validate_username]
Note for readers: make sure you override both model and form level validators!