0
0
mirror of https://github.com/django/django.git synced 2024-11-29 14:46:18 +01:00

Fixed #17927 -- Added initial values support for BaseGenericInlineFormSet

Thanks Fak3 for the suggestion.
This commit is contained in:
Bojan Mihelac 2013-04-09 18:24:54 +02:00 committed by Tim Graham
parent a35ed20241
commit b00c6371af
2 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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