Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1661 -- Added logic for string-form model references in the 't…

…o' argument of OneToOneFields. Includes regression test.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dc473309ef15e88a41845a52485eb6d38f819637 1 parent 6cbdbff
Russell Keith-Magee authored June 23, 2006
7  django/db/models/fields/related.py
@@ -515,8 +515,13 @@ def contribute_to_related_class(self, cls, related):
25  tests/regressiontests/string_lookup/models.py
@@ -21,9 +21,22 @@ class Whiz(models.Model):
21 21
     def __str__(self):
22 22
         return "Whiz %s" % self.name
23 23
 
  24
+class Child(models.Model):
  25
+    parent = models.OneToOneField('Base')
  26
+    name = models.CharField(maxlength = 50)
  27
+
  28
+    def __str__(self):
  29
+        return "Child %s" % self.name
  30
+    
  31
+class Base(models.Model):
  32
+    name = models.CharField(maxlength = 50)
  33
+
  34
+    def __str__(self):
  35
+        return "Base %s" % self.name
  36
+
24 37
 API_TESTS = """
25  
-# Regression test for #1662: Check that string form referencing of models works, both as
26  
-# pre and post reference
  38
+# Regression test for #1661 and #1662: Check that string form referencing of models works, 
  39
+# both as pre and post reference, on all RelatedField types.
27 40
 
28 41
 >>> f1 = Foo(name="Foo1")
29 42
 >>> f1.save()
@@ -45,4 +58,12 @@ def __str__(self):
45 58
 >>> b1.back
46 59
 <Foo: Foo Foo1>
47 60
 
  61
+>>> base1 = Base(name="Base1")
  62
+>>> base1.save()
  63
+
  64
+>>> child1 = Child(name="Child1", parent=base1)
  65
+>>> child1.save()
  66
+
  67
+>>> child1.parent
  68
+<Base: Base Base1>
48 69
 """

0 notes on commit dc47330

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