Ticket #17594: formset-tweak-109-v2.patch

File formset-tweak-109-v2.patch, 1.4 KB (added by Travis Swicegood, 13 years ago)

Tweak based on feedback

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 15d5041..cd8f027 100644
    a b class BaseModelFormSet(BaseFormSet):  
    591591    def save_existing_objects(self, commit=True):
    592592        self.changed_objects = []
    593593        self.deleted_objects = []
    594         if not self.get_queryset():
     594        if not self.initial_forms:
    595595            return []
    596596
    597597        saved_instances = []
  • tests/regressiontests/model_formsets_regress/tests.py

    diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py
    index 613d776..f1e935e 100644
    a b class FormsetTests(TestCase):  
    249249        self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11")
    250250        self.assertTrue(u'value="apollo12"' in formset.extra_forms[1].as_p())
    251251
     252    def test_extraneous_query_is_not_run(self):
     253        Formset = modelformset_factory(Network)
     254        data = {u'test-TOTAL_FORMS': u'1',
     255                u'test-INITIAL_FORMS': u'0',
     256                u'test-MAX_NUM_FORMS': u'',
     257                u'test-0-name': u'Random Place', }
     258        with self.assertNumQueries(1):
     259            formset = Formset(data, prefix="test")
     260            formset.save()
     261
     262
    252263class CustomWidget(forms.CharField):
    253264    pass
    254265
Back to Top