Created
September 2, 2015 16:47
-
-
Save loic/5ff7b4dc2ce970c573ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/forms/models.py b/django/forms/models.py | |
index 31e4bba..8a70baa 100644 | |
--- a/django/forms/models.py | |
+++ b/django/forms/models.py | |
@@ -391,7 +391,13 @@ class BaseModelForm(BaseForm): | |
# Override any validation error messages defined at the model level | |
# with those defined at the form level. | |
opts = self._meta | |
- for field, messages in errors.error_dict.items(): | |
+ | |
+ if hasattr(errors, 'error_dict'): | |
+ error_dict = errors.error_dict | |
+ else: | |
+ error_dict = {NON_FIELD_ERRORS: errors} | |
+ | |
+ for field, messages in error_dict.items(): | |
if (field == NON_FIELD_ERRORS and opts.error_messages and | |
NON_FIELD_ERRORS in opts.error_messages): | |
error_messages = opts.error_messages[NON_FIELD_ERRORS] | |
@@ -423,8 +429,10 @@ class BaseModelForm(BaseForm): | |
if isinstance(field, InlineForeignKeyField): | |
exclude.append(name) | |
- # Update the model instance with self.cleaned_data. | |
- self.instance = construct_instance(self, self.instance, opts.fields, exclude) | |
+ try: | |
+ self.instance = construct_instance(self, self.instance, opts.fields, exclude) | |
+ except ValidationError as e: | |
+ self._update_errors(e) | |
try: | |
self.instance.full_clean(exclude=exclude, validate_unique=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment