Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@freakboy3742 freakboy3742 authored
View
5 django/views/generic/edit.py
@@ -72,10 +72,7 @@ def get_form_class(self):
if self.form_class:
return self.form_class
else:
- if self.model is None:
- model = self.queryset.model
- else:
- model = self.model
+ model = self.get_queryset().model
return model_forms.modelform_factory(model)
def get_form(self, form_class):
View
4 tests/regressiontests/generic_views/edit.py
@@ -7,6 +7,10 @@
from regressiontests.generic_views.models import Artist, Author
from regressiontests.generic_views import views
+class ModelFormMixinTests(TestCase):
+ def test_get_form(self):
+ form_class = views.AuthorGetQuerySetFormView().get_form_class()
+ self.assertEqual(form_class.Meta.model, Author)
class CreateViewTests(TestCase):
urls = 'regressiontests.generic_views.urls'
View
2  tests/regressiontests/generic_views/tests.py
@@ -1,5 +1,5 @@
from regressiontests.generic_views.base import ViewTest, TemplateViewTest, RedirectViewTest
from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests
from regressiontests.generic_views.detail import DetailViewTest
-from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests
+from regressiontests.generic_views.edit import ModelFormMixinTests, CreateViewTests, UpdateViewTests, DeleteViewTests
from regressiontests.generic_views.list import ListViewTests
View
4 tests/regressiontests/generic_views/views.py
@@ -143,3 +143,7 @@ class BookTodayArchive(BookConfig, generic.TodayArchiveView):
class BookDetail(BookConfig, generic.DateDetailView):
pass
+
+class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
+ def get_queryset(self):
+ return Author.objects.all()
Please sign in to comment.
Something went wrong with that request. Please try again.