diff --git a/django/forms/models.py b/django/forms/models.py
index 595b775..d62a2ce 100644
a
|
b
|
def fields_for_model(model, fields=None, exclude=None, formfield_callback=lambda
|
163 | 163 | field_list.append((f.name, formfield)) |
164 | 164 | field_dict = SortedDict(field_list) |
165 | 165 | if fields: |
166 | | field_dict = SortedDict([(f, field_dict[f]) for f in fields if (not exclude) or (exclude and f not in exclude)]) |
| 166 | field_dict = SortedDict([(f, field_dict.get(f)) for f in fields if (not exclude) or (exclude and f not in exclude)]) |
167 | 167 | return field_dict |
168 | 168 | |
169 | 169 | class ModelFormOptions(object): |
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 9261900..4075250 100644
a
|
b
|
ValidationError: [u'Select a valid choice. z is not one of the available choices
|
1450 | 1450 | >>> core.parent |
1451 | 1451 | <Inventory: Pear> |
1452 | 1452 | |
| 1453 | >>> class CategoryForm(ModelForm): |
| 1454 | ... description = forms.CharField() |
| 1455 | ... class Meta: |
| 1456 | ... model = Category |
| 1457 | ... fields = ['description', 'url'] |
| 1458 | |
| 1459 | >>> CategoryForm.base_fields.keys() |
| 1460 | ['description', 'url'] |
| 1461 | |
| 1462 | >>> print CategoryForm() |
| 1463 | <tr><th><label for="id_description">Description:</label></th><td><input type="text" name="description" id="id_description" /></td></tr> |
| 1464 | <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr> |
| 1465 | |
1453 | 1466 | # Clean up |
1454 | 1467 | >>> import shutil |
1455 | 1468 | >>> shutil.rmtree(temp_storage_dir) |