Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #16986 -- Model.clean() can report errors on individual fields. #1441

Merged
merged 1 commit into from
Aug 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/model_forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.')]})
8 changes: 8 additions & 0 deletions tests/model_forms/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down