1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #26238 -- Raised explicit error for non-editable field in ModelForm

Thanks Luke Crouch for the report and Simon Charette for the review.
This commit is contained in:
Claude Paroz
2016-02-20 14:40:07 +01:00
parent 6670da75ff
commit d43156e1e9
3 changed files with 23 additions and 1 deletions

View File

@@ -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