Skip to content

Commit

Permalink
Fixed #14572 -- generic_inlineformset_factory shouldn't specify defau…
Browse files Browse the repository at this point in the history
…lt formfield_callback. Thanks prestontimmons!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16234 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
honzakral committed May 17, 2011
1 parent 578a31f commit ee8f6ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/contrib/contenttypes/generic.py
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions tests/modeltests/generic_relations/tests.py
@@ -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
Expand Down Expand Up @@ -221,3 +222,23 @@ def test_generic_inline_formsets(self):
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))

0 comments on commit ee8f6ca

Please sign in to comment.