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):
|
591 | 591 | def save_existing_objects(self, commit=True): |
592 | 592 | self.changed_objects = [] |
593 | 593 | self.deleted_objects = [] |
594 | | if not self.get_queryset(): |
| 594 | if not self.initial_forms: |
595 | 595 | return [] |
596 | 596 | |
597 | 597 | saved_instances = [] |
diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
index 8e2150c..c50dafb 100644
a
|
b
|
|
13 | 13 | CustomDateTimeInputFormatsTests, SimpleDateTimeFormatTests) |
14 | 14 | from .media import FormsMediaTestCase, StaticFormsMediaTestCase |
15 | 15 | from .models import (TestTicket12510, ModelFormCallableModelDefault, |
16 | | FormsModelTestCase, RelatedModelFormTests) |
| 16 | FormsModelTestCase, RelatedModelFormTests, ModelFormsetTests) |
17 | 17 | from .regressions import FormsRegressionsTestCase |
18 | 18 | from .util import FormsUtilTestCase |
19 | 19 | from .validators import TestFieldWithValidators |
diff --git a/tests/regressiontests/forms/tests/models.py b/tests/regressiontests/forms/tests/models.py
index 1254608..497b3c1 100644
a
|
b
|
|
6 | 6 | from django.core.files.uploadedfile import SimpleUploadedFile |
7 | 7 | from django.db import models |
8 | 8 | from django.forms import Form, ModelForm, FileField, ModelChoiceField |
9 | | from django.forms.models import ModelFormMetaclass |
| 9 | from django.forms.models import ModelFormMetaclass, modelformset_factory |
10 | 10 | from django.test import TestCase |
11 | 11 | |
12 | 12 | from ..models import (ChoiceOptionModel, ChoiceFieldModel, FileModel, Group, |
13 | | BoundaryModel, Defaults) |
| 13 | BoundaryModel, Defaults, Cheese) |
14 | 14 | |
15 | 15 | |
16 | 16 | class ChoiceFieldForm(ModelForm): |
… |
… |
class Meta:
|
196 | 196 | model=A |
197 | 197 | |
198 | 198 | self.assertTrue(issubclass(ModelFormMetaclass('Form', (ModelForm,), {'Meta': Meta}), ModelForm)) |
| 199 | |
| 200 | |
| 201 | class 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() |