mirror of
https://github.com/django/django.git
synced 2025-11-03 05:13:23 +00:00
Fixed #10405 -- Raise a more useful error if the formfield of a related 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
This commit is contained in:
parent
386b12c1c6
commit
1d485cf14f
3 changed files with 38 additions and 1 deletions
|
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import models
|
||||
from django.forms import Form, ModelForm, FileField, ModelChoiceField
|
||||
from django.forms.models import ModelFormMetaclass
|
||||
from django.test import TestCase
|
||||
from regressiontests.forms.models import (ChoiceOptionModel, ChoiceFieldModel,
|
||||
FileModel, Group, BoundaryModel, Defaults)
|
||||
|
|
@ -160,3 +162,34 @@ class FormsModelTestCase(TestCase):
|
|||
self.assertEqual(obj.name, u'class default value')
|
||||
self.assertEqual(obj.value, 99)
|
||||
self.assertEqual(obj.def_date, datetime.date(1999, 3, 2))
|
||||
|
||||
class RelatedModelFormTests(TestCase):
|
||||
def test_invalid_loading_order(self):
|
||||
"""
|
||||
Test for issue 10405
|
||||
"""
|
||||
class A(models.Model):
|
||||
ref = models.ForeignKey("B")
|
||||
|
||||
class Meta:
|
||||
model=A
|
||||
|
||||
self.assertRaises(ValueError, ModelFormMetaclass, 'Form', (ModelForm,), {'Meta': Meta})
|
||||
|
||||
class B(models.Model):
|
||||
pass
|
||||
|
||||
def test_valid_loading_order(self):
|
||||
"""
|
||||
Test for issue 10405
|
||||
"""
|
||||
class A(models.Model):
|
||||
ref = models.ForeignKey("B")
|
||||
|
||||
class B(models.Model):
|
||||
pass
|
||||
|
||||
class Meta:
|
||||
model=A
|
||||
|
||||
self.assertTrue(issubclass(ModelFormMetaclass('Form', (ModelForm,), {'Meta': Meta}), ModelForm))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue