Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #10512 -- Corrected the handling of extra fields on a ModelForm…

…. Thanks to Alex Gaynor for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10070 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cf7a3fa7f06814a7a22198fb9f84f6b9c0f09461 1 parent 536ccd1
Russell Keith-Magee freakboy3742 authored
Showing with 14 additions and 1 deletion.
  1. +1 −1  django/forms/models.py
  2. +13 −0 tests/modeltests/model_forms/models.py
2  django/forms/models.py
View
@@ -163,7 +163,7 @@ def fields_for_model(model, fields=None, exclude=None, formfield_callback=lambda
field_list.append((f.name, formfield))
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)])
+ field_dict = SortedDict([(f, field_dict.get(f)) for f in fields if (not exclude) or (exclude and f not in exclude)])
return field_dict
class ModelFormOptions(object):
13 tests/modeltests/model_forms/models.py
View
@@ -1450,6 +1450,19 @@ def __unicode__(self):
>>> core.parent
<Inventory: Pear>
+>>> class CategoryForm(ModelForm):
+... description = forms.CharField()
+... class Meta:
+... model = Category
+... fields = ['description', 'url']
+
+>>> CategoryForm.base_fields.keys()
+['description', 'url']
+
+>>> print CategoryForm()
+<tr><th><label for="id_description">Description:</label></th><td><input type="text" name="description" id="id_description" /></td></tr>
+<tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
+
# Clean up
>>> import shutil
>>> shutil.rmtree(temp_storage_dir)
Please sign in to comment.
Something went wrong with that request. Please try again.