Fixed #14797 -- Corrected the handling of get_form_class() when a custom 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
This commit is contained in:
Russell Keith-Magee 2010-12-04 11:20:52 +00:00
parent 324658ef26
commit adfd7f8172
4 changed files with 10 additions and 5 deletions

View File

@ -72,10 +72,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
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 File

@ -7,6 +7,10 @@ from django.utils.unittest import expectedFailure
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 File

@ -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 File

@ -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()