Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… have a model class defined. Thanks, tobias.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8da76ffeaa47547edb24f99a55f8c9e1a8986b90 1 parent 7aeb37d
Joseph Kocherhans authored February 23, 2010
2  django/forms/models.py
@@ -236,6 +236,8 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
236 236
                  empty_permitted=False, instance=None):
237 237
         opts = self._meta
238 238
         if instance is None:
  239
+            if opts.model is None:
  240
+                raise ValueError('ModelForm has no model class specified.')
239 241
             # if we didn't get an instance, instantiate a new one
240 242
             self.instance = opts.model()
241 243
             object_data = {}
7  tests/regressiontests/model_forms_regress/tests.py
@@ -145,5 +145,10 @@ def test_string_message(self):
145 145
         data = {'name': 'anonymous'}
146 146
         form = RealPersonForm(data)
147 147
         self.assertEqual(form.is_valid(), False)
148  
-        self.assertEqual(form.errors['__all__'], ['Please specify a real name.']) 
  148
+        self.assertEqual(form.errors['__all__'], ['Please specify a real name.'])
149 149
 
  150
+class ModelClassTests(TestCase):
  151
+    def test_no_model_class(self):
  152
+        class NoModelModelForm(forms.ModelForm):
  153
+            pass
  154
+        self.assertRaises(ValueError, NoModelModelForm)

0 notes on commit 8da76ff

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