django overwrite form clean method
- by John
Hi,
When overwriting a form clean method how do you know if its failed validation on any of the fields? e.g. in the form below if I overwrite the clean method how do I know if the form has failed validation on any of the fields?
class PersonForm(forms.Form):
title = Forms.CharField(max_length=100)
first_name = Forms.CharField(max_length=100)
surname = Forms.CharField(max_length=100)
password = Forms.CharField(max_length=100)
def clean(self, value):
cleaned_data = self.cleaned_data
IF THE FORM HAS FAILED VALIDATION:
self.data['password'] = 'abc'
raise forms.ValidationError("You have failed validation!")
ELSE:
return cleaned_data
Thanks