Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #11872 -- Instantiate the correct model in BaseInlineFo…

…rmSet.__init__ when instance is None. Thanks tobias.

Backport of [11688] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11689 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 53275a4775ac22934170312aa2e3c7f0b1e4c4e7 1 parent a429943
@brosner brosner authored
View
2  django/forms/models.py
@@ -709,7 +709,7 @@ def __init__(self, data=None, files=None, instance=None,
save_as_new=False, prefix=None):
from django.db.models.fields.related import RelatedObject
if instance is None:
- self.instance = self.model()
+ self.instance = self.fk.rel.to()
else:
self.instance = instance
self.save_as_new = save_as_new
View
10 tests/regressiontests/model_formsets_regress/tests.py
@@ -140,3 +140,13 @@ def test_formset_over_inherited_model(self):
self.assertEqual(manager[1]['name'], 'Terry Gilliam')
else:
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)
Please sign in to comment.
Something went wrong with that request. Please try again.