diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2014-11-18 17:58:43 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-11-21 13:02:40 -0500 |
| commit | f91c6ecc223dbed05f6640af515e8b56895170ac (patch) | |
| tree | 46612126d96e5af95aaa6c6fa2352f429e26f621 /tests | |
| parent | 910dcd574a4dff47abb78476e918fb6a9908cd23 (diff) | |
[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 5b26a014a81ba0d404d46e11d2b45c01d92b97e5 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_forms/models.py | 2 | ||||
| -rw-r--r-- | tests/model_forms/tests.py | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index 8936a17fc0..d54cccfe80 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -386,6 +386,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.") diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 489137bd35..78c3bca416 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -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()) |
