diff -r ee4db7b4f9ef django/forms/models.py
a
|
b
|
|
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 = {} |
diff -r ee4db7b4f9ef tests/regressiontests/model_forms_regress/tests.py
a
|
b
|
|
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) |