Ticket #10750: 10750_baseinlineformset_savenew.diff
File 10750_baseinlineformset_savenew.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
546 546 # save the object. 547 547 obj = form.save(commit=False) 548 548 setattr(obj, self.fk.get_attname(), self.instance.pk) 549 obj.save() 549 if commit: 550 obj.save() 550 551 # form.save_m2m() can be called via the formset later on if commit=False 551 552 if commit and hasattr(form, 'save_m2m'): 552 553 form.save_m2m() -
tests/regressiontests/inline_formsets/tests.py
(this hunk was shorter than expected) 1 1 from django.test import TestCase 2 2 from django.forms.models import inlineformset_factory 3 from regressiontests.inline_formsets.models import Poet, Poem 3 from regressiontests.inline_formsets.models import Poet, Poem, School, Parent, Child 4 4 5 5 class DeletionTests(TestCase): 6 6 def test_deletion(self): … … 74 75 self.assertEqual(formset.is_valid(), True) 75 76 formset.save() 76 77 self.assertEqual(Poem.objects.count(), 0) 78 79 def test_save_new(self): 80 """ 81 Make sure inlineformsets respect commit=False 82 regression for #10750 83 """ 84 # exclude some required field from the forms 85 ChildFormSet = inlineformset_factory(School, Child, exclude=['father', 'mother']) 86 school = School.objects.create(name=u'test') 87 mother = Parent.objects.create(name=u'mother') 88 father = Parent.objects.create(name=u'father') 89 data = { 90 'child_set-TOTAL_FORMS': u'1', 91 'child_set-INITIAL_FORMS': u'0', 92 'child_set-0-name': u'child', 93 } 94 formset = ChildFormSet(data, instance=school) 95 self.assertEqual(formset.is_valid(), True) 96 objects = formset.save(commit=False) 97 for obj in objects: 98 obj.mother = mother 99 obj.father = father 100 obj.save() 101 self.assertEqual(school.child_set.count(), 1) 102