mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #17594 -- Stopped ModelFormset.save from running a SELECT query by relying on the fact that the initial form is already set. Thanks, tswicegood.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17434 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -591,7 +591,7 @@ class BaseModelFormSet(BaseFormSet): | |||||||
|     def save_existing_objects(self, commit=True): |     def save_existing_objects(self, commit=True): | ||||||
|         self.changed_objects = [] |         self.changed_objects = [] | ||||||
|         self.deleted_objects = [] |         self.deleted_objects = [] | ||||||
|         if not self.get_queryset(): |         if not self.initial_forms: | ||||||
|             return [] |             return [] | ||||||
|  |  | ||||||
|         saved_instances = [] |         saved_instances = [] | ||||||
|   | |||||||
| @@ -249,6 +249,17 @@ class FormsetTests(TestCase): | |||||||
|         self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11") |         self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11") | ||||||
|         self.assertTrue(u'value="apollo12"' in formset.extra_forms[1].as_p()) |         self.assertTrue(u'value="apollo12"' in formset.extra_forms[1].as_p()) | ||||||
|  |  | ||||||
|  |     def test_extraneous_query_is_not_run(self): | ||||||
|  |         Formset = modelformset_factory(Network) | ||||||
|  |         data = {u'test-TOTAL_FORMS': u'1', | ||||||
|  |                 u'test-INITIAL_FORMS': u'0', | ||||||
|  |                 u'test-MAX_NUM_FORMS': u'', | ||||||
|  |                 u'test-0-name': u'Random Place', } | ||||||
|  |         with self.assertNumQueries(1): | ||||||
|  |             formset = Formset(data, prefix="test") | ||||||
|  |             formset.save() | ||||||
|  |  | ||||||
|  |  | ||||||
| class CustomWidget(forms.CharField): | class CustomWidget(forms.CharField): | ||||||
|     pass |     pass | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user