1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #23865 -- documented how to assign errors to a field in Model.clean()

Also added a unit test wit the simpler syntax which we have documented,
where the dictionary values are strings.
This commit is contained in:
Alasdair Nicol
2014-11-18 17:58:43 +00:00
committed by Tim Graham
parent a3aeba0f95
commit 5b26a014a8
3 changed files with 26 additions and 3 deletions

View File

@@ -381,6 +381,8 @@ class CustomErrorMessage(models.Model):
def clean(self):
if self.name1 == 'FORBIDDEN_VALUE':
raise ValidationError({'name1': [ValidationError('Model.clean() error messages.')]})
elif self.name1 == 'FORBIDDEN_VALUE2':
raise ValidationError({'name1': 'Model.clean() error messages (simpler syntax).'})
elif self.name1 == 'GLOBAL_ERROR':
raise ValidationError("Global error message.")