How can I add form validation and preferably with i18n localization? I tried something like the following which doesn’t work and needs to import Validationerror
class AForm(djangoforms.ModelForm):
def clean_name(self):
value = self.data['name']
if not value:
raise ValidationError("No name.")
return self.data['name']
def clean_email(self):
pass
If I get it to work can I raise a localized ValidationError like this?
ValidationError(_("No name."))
I haven’t used the Google app engine, so the import paths are probably wrong, but the pattern I’ve used before with standard Django is:
See the docs on field validation for further information.
Also, I presume that your actual application is more complicated than this – if you only want to check that the field is given, set the required attribute on the field and Django will do it for you.