1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[1.7.x] 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.

Backport of 5b26a014a8 from master
This commit is contained in:
Alasdair Nicol
2014-11-18 17:58:43 +00:00
committed by Tim Graham
parent 910dcd574a
commit f91c6ecc22
3 changed files with 26 additions and 3 deletions

View File

@@ -2207,6 +2207,13 @@ class ModelFormCustomErrorTests(TestCase):
str(form.errors['name1']),
'<ul class="errorlist"><li>Model.clean() error messages.</li></ul>'
)
data = {'name1': 'FORBIDDEN_VALUE2', 'name2': 'ABC'}
form = CustomErrorMessageForm(data)
self.assertFalse(form.is_valid())
self.assertHTMLEqual(
str(form.errors['name1']),
'<ul class="errorlist"><li>Model.clean() error messages (simpler syntax).</li></ul>'
)
data = {'name1': 'GLOBAL_ERROR', 'name2': 'ABC'}
form = CustomErrorMessageForm(data)
self.assertFalse(form.is_valid())