Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #12285. ModelForm raises a more informative error if it doesn't…

… have a model class defined. Thanks, tobias.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8da76ffeaa47547edb24f99a55f8c9e1a8986b90 1 parent 7aeb37d
@jkocherhans jkocherhans authored
2  django/forms/
@@ -236,6 +236,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 = {}
7 tests/regressiontests/model_forms_regress/
@@ -145,5 +145,10 @@ def test_string_message(self):
data = {'name': 'anonymous'}
form = RealPersonForm(data)
self.assertEqual(form.is_valid(), False)
- self.assertEqual(form.errors['__all__'], ['Please specify a real name.'])
+ self.assertEqual(form.errors['__all__'], ['Please specify a real name.'])
+class ModelClassTests(TestCase):
+ def test_no_model_class(self):
+ class NoModelModelForm(forms.ModelForm):
+ pass
+ self.assertRaises(ValueError, NoModelModelForm)

0 comments on commit 8da76ff

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