diff options
| author | Daniel Pyrathon <pirosb3@gmail.com> | 2015-01-06 19:16:35 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-06 19:25:12 -0500 |
| commit | fb48eb05816b1ac87d58696cdfe48be18c901f16 (patch) | |
| tree | 3d2e981b6f3fafdeb7310d0734fb148ebb7f6aef /django/forms/models.py | |
| parent | 749d23251bbd6564341405e6f8c1da129b8307e7 (diff) | |
Fixed #12663 -- Formalized the Model._meta API for retrieving fields.
Thanks to Russell Keith-Magee for mentoring this Google Summer of
Code 2014 project and everyone else who helped with the patch!
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index c57c8af0b9..443d0559a6 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -6,6 +6,7 @@ and database field objects. from __future__ import unicode_literals from collections import OrderedDict +from itertools import chain import warnings from django.core.exceptions import ( @@ -89,7 +90,7 @@ def save_instance(form, instance, fields=None, fail_message='saved', # Note that for historical reasons we want to include also # virtual_fields here. (GenericRelation was previously a fake # m2m field). - for f in opts.many_to_many + opts.virtual_fields: + for f in chain(opts.many_to_many, opts.virtual_fields): if not hasattr(f, 'save_form_data'): continue if fields and f.name not in fields: @@ -127,7 +128,7 @@ def model_to_dict(instance, fields=None, exclude=None): from django.db.models.fields.related import ManyToManyField opts = instance._meta data = {} - for f in opts.concrete_fields + opts.virtual_fields + opts.many_to_many: + for f in chain(opts.concrete_fields, opts.virtual_fields, opts.many_to_many): if not getattr(f, 'editable', False): continue if fields and f.name not in fields: @@ -186,7 +187,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None, from django.db.models.fields import Field as ModelField sortable_virtual_fields = [f for f in opts.virtual_fields if isinstance(f, ModelField)] - for f in sorted(opts.concrete_fields + sortable_virtual_fields + opts.many_to_many): + for f in sorted(chain(opts.concrete_fields, sortable_virtual_fields, opts.many_to_many)): if not getattr(f, 'editable', False): continue if fields is not None and f.name not in fields: |
