thirdparty/google_appengine/lib/django/tests/regressiontests/one_to_one_regress/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 Place(models.Model):
       
     4     name = models.CharField(maxlength=50)
       
     5     address = models.CharField(maxlength=80)
       
     6 
       
     7     def __str__(self):
       
     8         return "%s the place" % self.name
       
     9 
       
    10 class Restaurant(models.Model):
       
    11     place = models.OneToOneField(Place)
       
    12     serves_hot_dogs = models.BooleanField()
       
    13     serves_pizza = models.BooleanField()
       
    14 
       
    15     def __str__(self):
       
    16         return "%s the restaurant" % self.place.name
       
    17 
       
    18 class Favorites(models.Model):
       
    19     name = models.CharField(maxlength = 50)
       
    20     restaurants = models.ManyToManyField(Restaurant)
       
    21 
       
    22     def __str__(self):
       
    23         return "Favorites for %s" % self.name
       
    24 
       
    25 __test__ = {'API_TESTS':"""
       
    26 # Regression test for #1064 and #1506: Check that we create models via the m2m
       
    27 # relation if the remote model has a OneToOneField.
       
    28 >>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
       
    29 >>> p1.save()
       
    30 >>> r = Restaurant(place=p1, serves_hot_dogs=True, serves_pizza=False)
       
    31 >>> r.save()
       
    32 >>> f = Favorites(name = 'Fred')
       
    33 >>> f.save()
       
    34 >>> f.restaurants = [r]
       
    35 >>> f.restaurants.all()
       
    36 [<Restaurant: Demon Dogs the restaurant>]
       
    37 """}