Hi,
Ticket #16986 (Model.clean cannot report errors on individual fields)
was fixed in Django 1.7, but the new feature is not documented. The
Model.clean() docs still state:
> Any ValidationError exceptions raised by Model.clean() will be stored
> in a special key error dictionary key, NON_FIELD_ERRORS, that is used
> for errors that are tied to the entire model instead of to a specific
> field
The syntax to report an error on an individual field is to pass a dict
to the ValidationError constructor.
> def clean(self):
> if self.name1 == 'FORBIDDEN_VALUE':
> raise ValidationError({'name1':
[ValidationError('Model.clean() error messages.')]})
However, this is a private API. There seemed to be some debate in ticket
#20867 about whether or not to document it.
I'd be happy work on a patch to update the documentation, but I wanted
to check that it is ok to document this API.
cheers,
Alasdair
--
Alasdair Nicol
Developer, MEMSET
mail:
alas...@memset.com
web:
http://www.memset.com/
Memset Ltd., registration number 4504980.
Building 87, Dunsfold Park, Stovolds Hill, Cranleigh, Surrey, GU6 8TB, UK