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

File formset-tweak-109-v1.patch, 2.9 KB (added by Travis Swicegood, 13 years ago)
  • django/forms/models.py

    From a767cc80bdf7971cec2d86f8ceb33803d49cc9d1 Mon Sep 17 00:00:00 2001
    From: Travis Swicegood <development@domain51.com>
    Date: Wed, 25 Jan 2012 16:14:12 -0600
    Subject: [PATCH] Tweak so an extraneous query is not run
    
    ---
     django/forms/models.py                        |    2 +-
     tests/regressiontests/forms/tests/__init__.py |    2 +-
     tests/regressiontests/forms/tests/models.py   |   16 ++++++++++++++--
     3 files changed, 16 insertions(+), 4 deletions(-)
    
    diff --git a/django/forms/models.py b/django/forms/models.py
    index 15d5041..cd8f027 100644
    a b def get_form_error(self):  
    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/forms/tests/__init__.py

    diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
    index 8e2150c..c50dafb 100644
    a b  
    1313    CustomDateTimeInputFormatsTests, SimpleDateTimeFormatTests)
    1414from .media import FormsMediaTestCase, StaticFormsMediaTestCase
    1515from .models import (TestTicket12510, ModelFormCallableModelDefault,
    16     FormsModelTestCase, RelatedModelFormTests)
     16    FormsModelTestCase, RelatedModelFormTests, ModelFormsetTests)
    1717from .regressions import FormsRegressionsTestCase
    1818from .util import FormsUtilTestCase
    1919from .validators import TestFieldWithValidators
  • tests/regressiontests/forms/tests/models.py

    diff --git a/tests/regressiontests/forms/tests/models.py b/tests/regressiontests/forms/tests/models.py
    index 1254608..497b3c1 100644
    a b  
    66from django.core.files.uploadedfile import SimpleUploadedFile
    77from django.db import models
    88from django.forms import Form, ModelForm, FileField, ModelChoiceField
    9 from django.forms.models import ModelFormMetaclass
     9from django.forms.models import ModelFormMetaclass, modelformset_factory
    1010from django.test import TestCase
    1111
    1212from ..models import (ChoiceOptionModel, ChoiceFieldModel, FileModel, Group,
    13     BoundaryModel, Defaults)
     13    BoundaryModel, Defaults, Cheese)
    1414
    1515
    1616class ChoiceFieldForm(ModelForm):
    class Meta:  
    196196            model=A
    197197
    198198        self.assertTrue(issubclass(ModelFormMetaclass('Form', (ModelForm,), {'Meta': Meta}), ModelForm))
     199
     200
     201class ModelFormsetTests(TestCase):
     202    def test_extraneous_query_is_not_run(self):
     203        CheeseFormset = modelformset_factory(Cheese)
     204        data = {u'test-TOTAL_FORMS': u'1',
     205                u'test-INITIAL_FORMS': u'0',
     206                u'test-MAX_NUM_FORMS': u'',
     207                u'test-0-name': u'Say Cheese!', }
     208        with self.assertNumQueries(1):
     209            formset = CheeseFormset(data, prefix="test")
     210            formset.save()
Back to Top