I'm trying to override the default "A user with that Username already exists." error message displayed when entering an existing username in my custom UserChangeForm
form. Django version used: 1.6.1
Here's my code :
class CustomUserChangeForm(forms.ModelForm):
username = forms.RegexField(
label="User name", max_length=30, regex=r"^[\w.@+-]+$",
error_messages={
'invalid': ("My message for invalid"),
'unique': ("My message for unique") # <- THIS
}
)
class Meta:
model = get_user_model()
fields = ('username', 'first_name', 'last_name', 'email',)
But if I enter an existing username with this code, I still get the default "A user with that Username already exists." message. Note that the custom "My message for invalid" is displayed when entering a wrong username (with invalid characters).