summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms')
-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