Am I doing something wrong, or is this seriously what the developers expect me to write every time I want to check if two fields are the same?
def clean(self):
data = self.cleaned_data
if "password1" in data and "password2" in data:
if data["password1"] != data["password2"]:
self._errors["password2"] = self.error_class(['Passwords do not match.'])
del data['password2']
return data
And why do I have to validate that the username is unique?
def clean_username(self):
data = self.cleaned_data['username']
if User.objects.filter(username=data).exists():
raise ValidationError('Username already taken.')
return data
It's a ModelForm
. It should already know there's a unique constraint?