Fixed #14572 -- generic_inlineformset_factory shouldn't specify default formfield_callback. Thanks prestontimmons!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16234 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Honza Král 2011-05-17 12:45:02 +00:00
parent 578a31fea3
commit ee8f6ca405
2 changed files with 22 additions and 1 deletions

View File

@ -362,7 +362,7 @@ def generic_inlineformset_factory(model, form=ModelForm,
fields=None, exclude=None,
extra=3, can_order=False, can_delete=True,
max_num=None,
formfield_callback=lambda f: f.formfield()):
formfield_callback=None):
"""
Returns an ``GenericInlineFormSet`` for the given kwargs.

View File

@ -1,3 +1,4 @@
from django import forms
from django.contrib.contenttypes.generic import generic_inlineformset_factory
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
@ -221,3 +222,23 @@ class GenericRelationsTests(TestCase):
formset = GenericFormSet(instance=lion, prefix='x')
self.assertEqual(u''.join(form.as_p() for form in formset.forms), u"""<p><label for="id_x-0-tag">Tag:</label> <input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50" /></p>
<p><label for="id_x-0-DELETE">Delete:</label> <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE" /><input type="hidden" name="x-0-id" id="id_x-0-id" /></p>""")
class CustomWidget(forms.CharField):
pass
class TaggedItemForm(forms.ModelForm):
class Meta:
model = TaggedItem
widgets = {'tag': CustomWidget}
class GenericInlineFormsetTest(TestCase):
"""
Regression for #14572: Using base forms with widgets
defined in Meta should not raise errors.
"""
def test_generic_inlineformset_factory(self):
Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm)
form = Formset().forms[0]
self.assertTrue(isinstance(form['tag'].field.widget, CustomWidget))