Fixed #21967: Added check for object in ModelFormMixin.get_form_kwargs.
Thanks lagovas.lagovas at gmail.com for the report.
This commit is contained in:
parent
80cd64ee17
commit
75a96f06e9
|
@ -122,7 +122,8 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
|
||||||
Returns the keyword arguments for instantiating the form.
|
Returns the keyword arguments for instantiating the form.
|
||||||
"""
|
"""
|
||||||
kwargs = super(ModelFormMixin, self).get_form_kwargs()
|
kwargs = super(ModelFormMixin, self).get_form_kwargs()
|
||||||
kwargs.update({'instance': self.object})
|
if hasattr(self, 'object'):
|
||||||
|
kwargs.update({'instance': self.object})
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django import forms
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from django.views.generic.base import View
|
from django.views.generic.base import View
|
||||||
from django.views.generic.edit import FormMixin, CreateView
|
from django.views.generic.edit import FormMixin, ModelFormMixin, CreateView
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
from .models import Artist, Author
|
from .models import Artist, Author
|
||||||
|
@ -55,6 +55,12 @@ class ModelFormMixinTests(TestCase):
|
||||||
form_class = views.AuthorGetQuerySetFormView().get_form_class()
|
form_class = views.AuthorGetQuerySetFormView().get_form_class()
|
||||||
self.assertEqual(form_class._meta.model, Author)
|
self.assertEqual(form_class._meta.model, Author)
|
||||||
|
|
||||||
|
def test_get_form_checks_for_object(self):
|
||||||
|
mixin = ModelFormMixin()
|
||||||
|
mixin.request = RequestFactory().get('/')
|
||||||
|
self.assertEqual({'initial': {}, 'prefix': None},
|
||||||
|
mixin.get_form_kwargs())
|
||||||
|
|
||||||
|
|
||||||
class CreateViewTests(TestCase):
|
class CreateViewTests(TestCase):
|
||||||
urls = 'generic_views.urls'
|
urls = 'generic_views.urls'
|
||||||
|
|
Loading…
Reference in New Issue