diff options
author | Bojan Mihelac <bmihelac@mihelac.org> | 2013-04-09 18:24:54 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2013-06-05 07:59:59 -0400 |
commit | b00c6371afab778ab6c6206fb2dbb3f2c7f750b4 (patch) | |
tree | be98297025f0956056a2261f02dde530cc85e2e3 | |
parent | a35ed202419a054a9125ee6205a1a7b4eb3cb46d (diff) | |
download | django-b00c6371afab778ab6c6206fb2dbb3f2c7f750b4.tar.gz |
Fixed #17927 -- Added initial values support for BaseGenericInlineFormSet
Thanks Fak3 for the suggestion.
-rw-r--r-- | django/contrib/contenttypes/generic.py | 5 | ||||
-rw-r--r-- | tests/generic_relations/tests.py | 16 |
2 files changed, 19 insertions, 2 deletions
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 5a19f35e07..26db4ab171 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -384,7 +384,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet): """ def __init__(self, data=None, files=None, instance=None, save_as_new=None, - prefix=None, queryset=None): + prefix=None, queryset=None, **kwargs): opts = self.model._meta self.instance = instance self.rel_name = '-'.join(( @@ -403,7 +403,8 @@ class BaseGenericInlineFormSet(BaseModelFormSet): }) super(BaseGenericInlineFormSet, self).__init__( queryset=qs, data=data, files=files, - prefix=prefix + prefix=prefix, + **kwargs ) @classmethod diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 1ed4989df8..734b2e5143 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -247,6 +247,22 @@ class GenericRelationsTests(TestCase): TaggedItem.objects.create(content_object=granite, tag="countertop") self.assertEqual(Rock.objects.filter(tags__tag="countertop").count(), 1) + def test_generic_inline_formsets_initial(self): + """ + Test for #17927 Initial values support for BaseGenericInlineFormSet. + """ + quartz = Mineral.objects.create(name="Quartz", hardness=7) + + GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1) + ctype = ContentType.objects.get_for_model(quartz) + initial_data = [{ + 'tag': 'lizard', + 'content_type': ctype.pk, + 'object_id': quartz.pk, + }] + formset = GenericFormSet(initial=initial_data) + self.assertEqual(formset.forms[0].initial, initial_data[0]) + class CustomWidget(forms.TextInput): pass |