thirdparty/google_appengine/lib/django/tests/regressiontests/string_lookup/models.py
changeset 2866 a04b1e4126c4
parent 2864 2e0b0af889be
child 2868 9f7f269383f7
equal deleted inserted replaced
2864:2e0b0af889be 2866:a04b1e4126c4
     1 from django.db import models
       
     2 
       
     3 class Foo(models.Model):
       
     4     name = models.CharField(maxlength=50)
       
     5 
       
     6     def __str__(self):
       
     7         return "Foo %s" % self.name
       
     8 
       
     9 class Bar(models.Model):
       
    10     name = models.CharField(maxlength=50)
       
    11     normal = models.ForeignKey(Foo, related_name='normal_foo')
       
    12     fwd = models.ForeignKey("Whiz")
       
    13     back = models.ForeignKey("Foo")
       
    14 
       
    15     def __str__(self):
       
    16         return "Bar %s" % self.place.name
       
    17 
       
    18 class Whiz(models.Model):
       
    19     name = models.CharField(maxlength = 50)
       
    20 
       
    21     def __str__(self):
       
    22         return "Whiz %s" % self.name
       
    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 
       
    37 __test__ = {'API_TESTS':"""
       
    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.
       
    40 
       
    41 >>> f1 = Foo(name="Foo1")
       
    42 >>> f1.save()
       
    43 >>> f2 = Foo(name="Foo1")
       
    44 >>> f2.save()
       
    45 
       
    46 >>> w1 = Whiz(name="Whiz1")
       
    47 >>> w1.save()
       
    48 
       
    49 >>> b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
       
    50 >>> b1.save()
       
    51 
       
    52 >>> b1.normal
       
    53 <Foo: Foo Foo1>
       
    54 
       
    55 >>> b1.fwd
       
    56 <Whiz: Whiz Whiz1>
       
    57 
       
    58 >>> b1.back
       
    59 <Foo: Foo Foo1>
       
    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>
       
    69 """}