Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14797 -- Corrected the handling of get_form_class() when a cus…

…tom queryset has been defined, but a model hasn't. Thanks to Gabriel Grant for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit adfd7f81729b3bd7eaff8b86546c34b2207138b3 1 parent 324658e
Russell Keith-Magee authored December 04, 2010
5  django/views/generic/edit.py
@@ -72,10 +72,7 @@ def get_form_class(self):
72 72
         if self.form_class:
73 73
             return self.form_class
74 74
         else:
75  
-            if self.model is None:
76  
-                model = self.queryset.model
77  
-            else:
78  
-                model = self.model
  75
+            model = self.get_queryset().model
79 76
             return model_forms.modelform_factory(model)
80 77
 
81 78
     def get_form(self, form_class):
4  tests/regressiontests/generic_views/edit.py
@@ -7,6 +7,10 @@
7 7
 from regressiontests.generic_views.models import Artist, Author
8 8
 from regressiontests.generic_views import views
9 9
 
  10
+class ModelFormMixinTests(TestCase):
  11
+    def test_get_form(self):
  12
+        form_class = views.AuthorGetQuerySetFormView().get_form_class()
  13
+        self.assertEqual(form_class.Meta.model, Author)
10 14
 
11 15
 class CreateViewTests(TestCase):
12 16
     urls = 'regressiontests.generic_views.urls'
2  tests/regressiontests/generic_views/tests.py
... ...
@@ -1,5 +1,5 @@
1 1
 from regressiontests.generic_views.base import ViewTest, TemplateViewTest, RedirectViewTest
2 2
 from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests
3 3
 from regressiontests.generic_views.detail import DetailViewTest
4  
-from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests
  4
+from regressiontests.generic_views.edit import ModelFormMixinTests, CreateViewTests, UpdateViewTests, DeleteViewTests
5 5
 from regressiontests.generic_views.list import ListViewTests
4  tests/regressiontests/generic_views/views.py
@@ -143,3 +143,7 @@ class BookTodayArchive(BookConfig, generic.TodayArchiveView):
143 143
 
144 144
 class BookDetail(BookConfig, generic.DateDetailView):
145 145
     pass
  146
+
  147
+class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
  148
+    def get_queryset(self):
  149
+        return Author.objects.all()

0 notes on commit adfd7f8

Please sign in to comment.
Something went wrong with that request. Please try again.