1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #1662 -- Added resolver for string-form model references for models that have already been loaded, with tests to validate both forward and backward referenced model names. Light refactoring of model loading to make regression tests behave more like normal model loading. Also clarifies the text of some validation errors.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3195 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2006-06-23 04:37:00 +00:00
parent bc2d8cdbc6
commit 0d4b5b9b4a
6 changed files with 82 additions and 20 deletions

View File

@@ -0,0 +1,48 @@
from django.db import models
class Foo(models.Model):
name = models.CharField(maxlength=50)
def __str__(self):
return "Foo %s" % self.name
class Bar(models.Model):
name = models.CharField(maxlength=50)
normal = models.ForeignKey(Foo, related_name='normal_foo')
fwd = models.ForeignKey("Whiz")
back = models.ForeignKey("Foo")
def __str__(self):
return "Bar %s" % self.place.name
class Whiz(models.Model):
name = models.CharField(maxlength = 50)
def __str__(self):
return "Whiz %s" % self.name
API_TESTS = """
# Regression test for #1662: Check that string form referencing of models works, both as
# pre and post reference
>>> f1 = Foo(name="Foo1")
>>> f1.save()
>>> f2 = Foo(name="Foo1")
>>> f2.save()
>>> w1 = Whiz(name="Whiz1")
>>> w1.save()
>>> b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
>>> b1.save()
>>> b1.normal
<Foo: Foo Foo1>
>>> b1.fwd
<Whiz: Whiz Whiz1>
>>> b1.back
<Foo: Foo Foo1>
"""