mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
[1.1.X] Fixed #12285. ModelForm raises a more informative error if it doesn't have a model class defined. Backport of [12526] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c702e262ff
commit
d23f2249ea
@ -214,6 +214,8 @@ class BaseModelForm(BaseForm):
|
|||||||
empty_permitted=False, instance=None):
|
empty_permitted=False, instance=None):
|
||||||
opts = self._meta
|
opts = self._meta
|
||||||
if instance is None:
|
if instance is None:
|
||||||
|
if opts.model is None:
|
||||||
|
raise ValueError('ModelForm has no model class specified.')
|
||||||
# if we didn't get an instance, instantiate a new one
|
# if we didn't get an instance, instantiate a new one
|
||||||
self.instance = opts.model()
|
self.instance = opts.model()
|
||||||
object_data = {}
|
object_data = {}
|
||||||
|
@ -100,4 +100,10 @@ class CustomFieldSaveTests(TestCase):
|
|||||||
# It's enough that the form saves without error -- the custom save routine will
|
# It's enough that the form saves without error -- the custom save routine will
|
||||||
# generate an AssertionError if it is called more than once during save.
|
# generate an AssertionError if it is called more than once during save.
|
||||||
form = CFFForm(data = {'f': None})
|
form = CFFForm(data = {'f': None})
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
|
class ModelClassTests(TestCase):
|
||||||
|
def test_no_model_class(self):
|
||||||
|
class NoModelModelForm(forms.ModelForm):
|
||||||
|
pass
|
||||||
|
self.assertRaises(ValueError, NoModelModelForm)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user