From b00c6371afab778ab6c6206fb2dbb3f2c7f750b4 Mon Sep 17 00:00:00 2001 From: Bojan Mihelac Date: Tue, 9 Apr 2013 18:24:54 +0200 Subject: Fixed #17927 -- Added initial values support for BaseGenericInlineFormSet Thanks Fak3 for the suggestion. --- tests/generic_relations/tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/generic_relations') 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 -- cgit v1.2.1