> An alternate would be to implement a method that does this. > > def field_error(self, name, error): > self._errors = self._errors or ErrorDict() > self._errors.setdefault(name, ErrorList()) > self._errors[name].append(error)
I also have a pending PR for that: https://code.djangoproject.com/ticket/5335. So you could do `self._errors[name].append(error)` from within the form and `self.errors[name].append(error)` from outside. > Having to raise a ValidationError would prevent you from creating multiple > field errors from within `clean`. Not necessarily, the `ValidationError` constructor accepts a variety of scenarios: def clean(self): errors = {} if condition1: errors['field1'] = ValidationError('message1', code='code1') if condition2: errors['field2'] = ValidationError('message2', code='code2') raise ValidationError(errors) Note that in the example above, `ValidationError('message1', code='code1')` can also be a simple string, but if https://github.com/django/django/pull/1483 (yet another PR) goes in, passing an error code will become quite useful. -- Loic -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. For more options, visit https://groups.google.com/groups/opt_out.
