Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[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: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d23f2249ea9ec4563ba18cf0c9de4d53d138113b 1 parent c702e26
@jkocherhans jkocherhans authored
2  django/forms/
@@ -214,6 +214,8 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
empty_permitted=False, instance=None):
opts = self._meta
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
self.instance = opts.model()
object_data = {}
8 tests/regressiontests/model_forms_regress/
@@ -100,4 +100,10 @@ def test_save(self):
# 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.
form = CFFForm(data = {'f': None})
+class ModelClassTests(TestCase):
+ def test_no_model_class(self):
+ class NoModelModelForm(forms.ModelForm):
+ pass
+ self.assertRaises(ValueError, NoModelModelForm)

0 comments on commit d23f224

Please sign in to comment.
Something went wrong with that request. Please try again.