Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #21967: Added check for object in ModelFormMixin.get_form_kwargs.

Thanks lagovas.lagovas at gmail.com for the report.
  • Loading branch information...
commit 75a96f06e916dda9124da9ddf765f3b8d5530914 1 parent 80cd64e
@ryankask ryankask authored timgraham committed
View
3  django/views/generic/edit.py
@@ -122,7 +122,8 @@ def get_form_kwargs(self):
Returns the keyword arguments for instantiating the form.
"""
kwargs = super(ModelFormMixin, self).get_form_kwargs()
- kwargs.update({'instance': self.object})
+ if hasattr(self, 'object'):
+ kwargs.update({'instance': self.object})
return kwargs
def get_success_url(self):
View
8 tests/generic_views/test_edit.py
@@ -9,7 +9,7 @@
from django.test import TestCase
from django.test.client import RequestFactory
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 .models import Artist, Author
@@ -55,6 +55,12 @@ def test_get_form(self):
form_class = views.AuthorGetQuerySetFormView().get_form_class()
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):
urls = 'generic_views.urls'
Please sign in to comment.
Something went wrong with that request. Please try again.