summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-02-20 14:40:07 +0100
committerClaude Paroz <claude@2xlibre.net>2016-02-21 00:24:20 +0100
commitd43156e1e984d7e0848b7d4db218877a29d617b4 (patch)
tree689f1d81d61f47cf85dce6e8e1807aa08a2b6dcc /django
parent6670da75ff8a59b2ec0b465846e3f76aab9155b2 (diff)
Fixed #26238 -- Raised explicit error for non-editable field in ModelForm
Thanks Luke Crouch for the report and Simon Charette for the review.
Diffstat (limited to 'django')
-rw-r--r--django/forms/models.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 8e8c8cfb55..be9e63d144 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -148,6 +148,12 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
if isinstance(f, ModelField)]
for f in sorted(chain(opts.concrete_fields, sortable_virtual_fields, opts.many_to_many)):
if not getattr(f, 'editable', False):
+ if (fields is not None and f.name in fields and
+ (exclude is None or f.name not in exclude)):
+ raise FieldError(
+ "'%s' cannot be specified for %s model form as it is a non-editable field" % (
+ f.name, model.__name__)
+ )
continue
if fields is not None and f.name not in fields:
continue