Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1441 from loic/ticket16986

Fixed #16986 -- Model.clean() can report errors on individual fields.
  • Loading branch information...
commit 0b771fcf2923cef1b0d759fda79907c39ad733b4 2 parents 263b873 + 71093d2
@mjtamlyn mjtamlyn authored
Showing with 13 additions and 1 deletion.
  1. +5 −1 tests/model_forms/models.py
  2. +8 −0 tests/model_forms/tests.py
View
6 tests/model_forms/models.py
@@ -12,7 +12,7 @@
import tempfile
from django.core import validators
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
@@ -296,3 +296,7 @@ class CustomErrorMessage(models.Model):
name2 = models.CharField(max_length=50,
validators=[validators.validate_slug],
error_messages={'invalid': 'Model custom error message.'})
+
+ def clean(self):
+ if self.name1 == 'FORBIDDEN_VALUE':
+ raise ValidationError({'name1': [ValidationError('Model.clean() error messages.')]})
View
8 tests/model_forms/tests.py
@@ -1782,6 +1782,14 @@ def test_custom_error_messages(self) :
'<ul class="errorlist"><li>Model custom error message.</li></ul>'
)
+ def test_model_clean_error_messages(self) :
+ data = {'name1': 'FORBIDDEN_VALUE', 'name2': 'ABC'}
+ errors = CustomErrorMessageForm(data).errors
+ self.assertHTMLEqual(
+ str(errors['name1']),
+ '<ul class="errorlist"><li>Model.clean() error messages.</li></ul>'
+ )
+
class M2mHelpTextTest(TestCase):
"""Tests for ticket #9321."""
Please sign in to comment.
Something went wrong with that request. Please try again.