Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d23f2249ea9ec4563ba18cf0c9de4d53d138113b 1 parent c702e26
Joseph Kocherhans jkocherhans authored
2  django/forms/models.py
View
@@ -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/tests.py
View
@@ -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})
- form.save()
+ form.save()
+
+class ModelClassTests(TestCase):
+ def test_no_model_class(self):
+ class NoModelModelForm(forms.ModelForm):
+ pass
+ self.assertRaises(ValueError, NoModelModelForm)
Please sign in to comment.
Something went wrong with that request. Please try again.