django overwrite form clean method
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-03-12T12:00:10Z
Indexed on
2010/03/12
13:37 UTC
Read the original article
Hit count: 166
django
|django-forms
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
© Stack Overflow or respective owner