Ticket #14572: 14572.diff

File 14572.diff, 2.8 KB (added by Preston Timmons, 14 years ago)

Updated patch with tests

  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 76f8eaf..7efb603 100644
    a b def generic_inlineformset_factory(model, form=ModelForm,  
    365365                                  fields=None, exclude=None,
    366366                                  extra=3, can_order=False, can_delete=True,
    367367                                  max_num=None,
    368                                   formfield_callback=lambda f: f.formfield()):
     368                                  formfield_callback=None):
    369369    """
    370370    Returns an ``GenericInlineFormSet`` for the given kwargs.
    371371
    class GenericInlineModelAdmin(InlineModelAdmin):  
    399399    ct_fk_field = "object_id"
    400400    formset = BaseGenericInlineFormSet
    401401
    402     def get_formset(self, request, obj=None):
     402    def get_formset(self, request, obj=None, **kwargs):
    403403        if self.declared_fieldsets:
    404404            fields = flatten_fieldsets(self.declared_fieldsets)
    405405        else:
    class GenericInlineModelAdmin(InlineModelAdmin):  
    423423            "max_num": self.max_num,
    424424            "exclude": exclude
    425425        }
     426        defaults.update(kwargs)
    426427        return generic_inlineformset_factory(self.model, **defaults)
    427428
    428429class GenericStackedInline(GenericInlineModelAdmin):
  • tests/modeltests/generic_relations/tests.py

    diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
    index 3d25301..fcf7d70 100644
    a b  
     1from django import forms
    12from django.contrib.contenttypes.generic import generic_inlineformset_factory
    23from django.contrib.contenttypes.models import ContentType
    34from django.test import TestCase
    class GenericRelationsTests(TestCase):  
    221222        formset = GenericFormSet(instance=lion, prefix='x')
    222223        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>
    223224<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
     227class CustomWidget(forms.CharField):
     228    pass
     229
     230
     231class TaggedItemForm(forms.ModelForm):
     232    class Meta:
     233        model = TaggedItem
     234        widgets = {'tag': CustomWidget}
     235
     236
     237class GenericInlineFormsetTest(TestCase):
     238    """
     239    Regression for #14572: Using base forms with widgets
     240    defined in Meta should not raise errors.
     241    """
     242
     243    def test_generic_inlineformset_factory(self):
     244        Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm)
     245        form = Formset().forms[0]
     246        self.assertTrue(isinstance(form['tag'].field.widget, CustomWidget))
Back to Top