Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14572 -- generic_inlineformset_factory shouldn't specify defau…

…lt formfield_callback. Thanks prestontimmons!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16234 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ee8f6ca4054dc74f2846a3639dcdb7dc8c8b18b3 1 parent 578a31f
Honza Král authored
2  django/contrib/contenttypes/generic.py
@@ -362,7 +362,7 @@ def generic_inlineformset_factory(model, form=ModelForm,
362 362
                                   fields=None, exclude=None,
363 363
                                   extra=3, can_order=False, can_delete=True,
364 364
                                   max_num=None,
365  
-                                  formfield_callback=lambda f: f.formfield()):
  365
+                                  formfield_callback=None):
366 366
     """
367 367
     Returns an ``GenericInlineFormSet`` for the given kwargs.
368 368
 
21  tests/modeltests/generic_relations/tests.py
... ...
@@ -1,3 +1,4 @@
  1
+from django import forms
1 2
 from django.contrib.contenttypes.generic import generic_inlineformset_factory
2 3
 from django.contrib.contenttypes.models import ContentType
3 4
 from django.test import TestCase
@@ -221,3 +222,23 @@ def test_generic_inline_formsets(self):
221 222
         formset = GenericFormSet(instance=lion, prefix='x')
222 223
         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>
223 224
 <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>""")
  225
+
  226
+
  227
+class CustomWidget(forms.CharField):
  228
+    pass
  229
+
  230
+class TaggedItemForm(forms.ModelForm):
  231
+    class Meta:
  232
+        model = TaggedItem
  233
+        widgets = {'tag': CustomWidget}
  234
+
  235
+class GenericInlineFormsetTest(TestCase):
  236
+    """
  237
+    Regression for #14572: Using base forms with widgets
  238
+    defined in Meta should not raise errors.
  239
+    """
  240
+
  241
+    def test_generic_inlineformset_factory(self):
  242
+        Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm)
  243
+        form = Formset().forms[0]
  244
+        self.assertTrue(isinstance(form['tag'].field.widget, CustomWidget))

0 notes on commit ee8f6ca

Please sign in to comment.
Something went wrong with that request. Please try again.