Permalink
Browse files

Fixed #11872 -- Instantiate the correct model in BaseInlineFormSet.__…

…init__ when instance is None. Thanks tobias.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11688 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
brosner committed Oct 30, 2009
1 parent 8812060 commit 8dd4a28721918ee0f42f6698b2c7403f75b25646
Showing with 11 additions and 1 deletion.
  1. +1 −1 django/forms/models.py
  2. +10 −0 tests/regressiontests/model_formsets_regress/tests.py
View
@@ -705,7 +705,7 @@ def __init__(self, data=None, files=None, instance=None,
save_as_new=False, prefix=None): save_as_new=False, prefix=None):
from django.db.models.fields.related import RelatedObject from django.db.models.fields.related import RelatedObject
if instance is None: if instance is None:
self.instance = self.model() self.instance = self.fk.rel.to()
else: else:
self.instance = instance self.instance = instance
self.save_as_new = save_as_new self.save_as_new = save_as_new
@@ -140,3 +140,13 @@ def test_formset_over_inherited_model(self):
self.assertEqual(manager[1]['name'], 'Terry Gilliam') self.assertEqual(manager[1]['name'], 'Terry Gilliam')
else: else:
self.fail('Errors found on formset:%s' % form_set.errors) self.fail('Errors found on formset:%s' % form_set.errors)
def test_formset_with_none_instance(self):
"A formset with instance=None can be created. Regression for #11872"
Form = modelform_factory(User)
FormSet = inlineformset_factory(User, UserSite)
# Instantiate the Form and FormSet to prove
# you can create a formset with an instance of None
form = Form(instance=None)
formset = FormSet(instance=None)

0 comments on commit 8dd4a28

Please sign in to comment.