Ticket #11872: inline_formsets_none_instance.diff

File inline_formsets_none_instance.diff, 1.4 KB (added by Tobias McNulty, 15 years ago)

add ticket # to test in patch

  • django/forms/models.py

     
    709709                 save_as_new=False, prefix=None):
    710710        from django.db.models.fields.related import RelatedObject
    711711        if instance is None:
    712             self.instance = self.model()
     712            self.instance = self.fk.rel.to()
    713713        else:
    714714            self.instance = instance
    715715        self.save_as_new = save_as_new
  • tests/regressiontests/model_formsets_regress/tests.py

     
    140140            self.assertEqual(manager[1]['name'], 'Terry Gilliam')
    141141        else:
    142142            self.fail('Errors found on formset:%s' % form_set.errors)
     143
     144    def test_formset_with_none_instance(self):
     145        "A formset with instance=None can be created. Regression for #11872"
     146        Form = modelform_factory(User)
     147        FormSet = inlineformset_factory(User, UserSite)
     148
     149        # Instantiate the Form and FormSet to prove
     150        # you can create a formset with an instance of None
     151        form = Form(instance=None)
     152        form_set = FormSet(instance=None)
     153       
     154       
     155   
     156 No newline at end of file
Back to Top