diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-15 05:05:26 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-03-15 05:05:26 +0000 |
| commit | 7be4b9a4c005639f03fcd096c3a53fffcb7f210c (patch) | |
| tree | 1719b7912b1ff949b6ac17b08156ceb42071f56d /django | |
| parent | 24b9c65d3fd9b6fdff9397a03eb4ec9e6f1687c1 (diff) | |
Fixed #8164 -- Fields on a ModelForm are now ordered in the order specified in the fields attribute of the ModelForm's Meta class. Thanks to Alex Gaynor for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10062 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/models.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index bfc0b35803..595b775f4f 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -149,7 +149,6 @@ def fields_for_model(model, fields=None, exclude=None, formfield_callback=lambda fields will be excluded from the returned fields, even if they are listed in the ``fields`` argument. """ - # TODO: if fields is provided, it would be nice to return fields in that order field_list = [] opts = model._meta for f in opts.fields + opts.many_to_many: @@ -162,7 +161,10 @@ def fields_for_model(model, fields=None, exclude=None, formfield_callback=lambda formfield = formfield_callback(f) if formfield: field_list.append((f.name, formfield)) - return SortedDict(field_list) + field_dict = SortedDict(field_list) + if fields: + field_dict = SortedDict([(f, field_dict[f]) for f in fields if (not exclude) or (exclude and f not in exclude)]) + return field_dict class ModelFormOptions(object): def __init__(self, options=None): |
