Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10405 -- Raise a more useful error if the formfield of a relat…

…ed model field can't be created yet because the related model isn't loaded yet. Thanks ojii and charstring.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16604 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1d485cf14ffa58dbeb130db2d50aa147556e0244 1 parent 386b12c
Jannis Leidel authored August 12, 2011
2  django/core/exceptions.py
@@ -3,7 +3,7 @@
3 3
 """
4 4
 
5 5
 class DjangoRuntimeWarning(RuntimeWarning):
6  
-   pass
  6
+    pass
7 7
 
8 8
 class ObjectDoesNotExist(Exception):
9 9
     "The requested object does not exist"
4  django/db/models/fields/related.py
@@ -905,6 +905,10 @@ def contribute_to_related_class(self, cls, related):
33  tests/regressiontests/forms/tests/models.py
... ...
@@ -1,7 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import datetime
3 3
 from django.core.files.uploadedfile import SimpleUploadedFile
  4
+from django.db import models
4 5
 from django.forms import Form, ModelForm, FileField, ModelChoiceField
  6
+from django.forms.models import ModelFormMetaclass
5 7
 from django.test import TestCase
6 8
 from regressiontests.forms.models import (ChoiceOptionModel, ChoiceFieldModel,
7 9
     FileModel, Group, BoundaryModel, Defaults)
@@ -160,3 +162,34 @@ class Meta:
160 162
         self.assertEqual(obj.name, u'class default value')
161 163
         self.assertEqual(obj.value, 99)
162 164
         self.assertEqual(obj.def_date, datetime.date(1999, 3, 2))
  165
+
  166
+class RelatedModelFormTests(TestCase):
  167
+    def test_invalid_loading_order(self):
  168
+        """
  169
+        Test for issue 10405
  170
+        """
  171
+        class A(models.Model):
  172
+            ref = models.ForeignKey("B")
  173
+
  174
+        class Meta:
  175
+            model=A
  176
+
  177
+        self.assertRaises(ValueError, ModelFormMetaclass, 'Form', (ModelForm,), {'Meta': Meta})
  178
+
  179
+        class B(models.Model):
  180
+            pass
  181
+
  182
+    def test_valid_loading_order(self):
  183
+        """
  184
+        Test for issue 10405
  185
+        """
  186
+        class A(models.Model):
  187
+            ref = models.ForeignKey("B")
  188
+
  189
+        class B(models.Model):
  190
+            pass
  191
+
  192
+        class Meta:
  193
+            model=A
  194
+
  195
+        self.assertTrue(issubclass(ModelFormMetaclass('Form', (ModelForm,), {'Meta': Meta}), ModelForm))

0 notes on commit 1d485cf

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