diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2019-02-05 11:22:08 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-02-06 13:48:39 -0500 |
| commit | 24b82cd201e21060fbc02117dc16d1702877a1f3 (patch) | |
| tree | 7d36db9251700d0abf8fbf69399c8abc7fd9026a /django/forms/models.py | |
| parent | 21bb71ef0dcb86798edb0d8b21138bcc4b947590 (diff) | |
Fixed #30159 -- Removed unneeded use of OrderedDict.
Dicts preserve order since Python 3.6.
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index fe8a67ed2b..d157c291ef 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -3,7 +3,6 @@ Helper functions for creating Form classes from Django models and database field objects. """ -from collections import OrderedDict from itertools import chain from django.core.exceptions import ( @@ -105,7 +104,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None, labels=None, help_texts=None, error_messages=None, field_classes=None, *, apply_limit_choices_to=True): """ - Return an ``OrderedDict`` containing form fields for the given model. + Return a dictionary containing form fields for the given model. ``fields`` is an optional list of field names. If provided, return only the named fields. @@ -134,7 +133,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None, ``apply_limit_choices_to`` is a boolean indicating if limit_choices_to should be applied to a field's queryset. """ - field_list = [] + field_dict = {} ignored = [] opts = model._meta # Avoid circular import @@ -178,15 +177,14 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None, if formfield: if apply_limit_choices_to: apply_limit_choices_to_to_formfield(formfield) - field_list.append((f.name, formfield)) + field_dict[f.name] = formfield else: ignored.append(f.name) - field_dict = OrderedDict(field_list) if fields: - field_dict = OrderedDict( - [(f, field_dict.get(f)) for f in fields - if ((not exclude) or (exclude and f not in exclude)) and (f not in ignored)] - ) + field_dict = { + f: field_dict.get(f) for f in fields + if (not exclude or f not in exclude) and f not in ignored + } return field_dict |
