thirdparty/google_appengine/lib/django/tests/modeltests/model_inheritance/models.py
changeset 2866 a04b1e4126c4
parent 2864 2e0b0af889be
child 2868 9f7f269383f7
equal deleted inserted replaced
2864:2e0b0af889be 2866:a04b1e4126c4
     1 """
       
     2 XX. Model inheritance
       
     3 
       
     4 Model inheritance isn't yet supported.
       
     5 """
       
     6 
       
     7 from django.db import models
       
     8 
       
     9 class Place(models.Model):
       
    10     name = models.CharField(maxlength=50)
       
    11     address = models.CharField(maxlength=80)
       
    12 
       
    13     def __str__(self):
       
    14         return "%s the place" % self.name
       
    15 
       
    16 class Restaurant(Place):
       
    17     serves_hot_dogs = models.BooleanField()
       
    18     serves_pizza = models.BooleanField()
       
    19 
       
    20     def __str__(self):
       
    21         return "%s the restaurant" % self.name
       
    22 
       
    23 class ItalianRestaurant(Restaurant):
       
    24     serves_gnocchi = models.BooleanField()
       
    25 
       
    26     def __str__(self):
       
    27         return "%s the italian restaurant" % self.name
       
    28 
       
    29 __test__ = {'API_TESTS':"""
       
    30 # Make sure Restaurant has the right fields in the right order.
       
    31 >>> [f.name for f in Restaurant._meta.fields]
       
    32 ['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza']
       
    33 
       
    34 # Make sure ItalianRestaurant has the right fields in the right order.
       
    35 >>> [f.name for f in ItalianRestaurant._meta.fields]
       
    36 ['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza', 'serves_gnocchi']
       
    37 
       
    38 # Create a couple of Places.
       
    39 >>> p1 = Place(name='Master Shakes', address='666 W. Jersey')
       
    40 >>> p1.save()
       
    41 >>> p2 = Place(name='Ace Hardware', address='1013 N. Ashland')
       
    42 >>> p2.save()
       
    43 
       
    44 # Test constructor for Restaurant.
       
    45 >>> r = Restaurant(name='Demon Dogs', address='944 W. Fullerton', serves_hot_dogs=True, serves_pizza=False)
       
    46 >>> r.save()
       
    47 
       
    48 # Test the constructor for ItalianRestaurant.
       
    49 >>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True)
       
    50 >>> ir.save()
       
    51 
       
    52 
       
    53 """}