Skip to content

Instantly share code, notes, and snippets.

@loic
Created September 2, 2015 16:43
Show Gist options
  • Save loic/9da0f355a33285c03639 to your computer and use it in GitHub Desktop.
Save loic/9da0f355a33285c03639 to your computer and use it in GitHub Desktop.
diff --git a/django/forms/models.py b/django/forms/models.py
index 31e4bba..38eacef 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,10 +429,8 @@ 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)
self.instance.full_clean(exclude=exclude, validate_unique=False)
except ValidationError as e:
self._update_errors(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment