2006-05-02 01:31:56 +00:00
|
|
|
"""
|
|
|
|
XX. Model inheritance
|
|
|
|
|
2006-05-31 18:45:17 +00:00
|
|
|
Model inheritance isn't yet supported.
|
2006-05-02 01:31:56 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
class Place(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
address = models.CharField(max_length=80)
|
2006-05-02 01:31:56 +00:00
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s the place" % self.name
|
2006-05-02 01:31:56 +00:00
|
|
|
|
|
|
|
class Restaurant(Place):
|
|
|
|
serves_hot_dogs = models.BooleanField()
|
|
|
|
serves_pizza = models.BooleanField()
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s the restaurant" % self.name
|
2006-05-02 01:31:56 +00:00
|
|
|
|
|
|
|
class ItalianRestaurant(Restaurant):
|
|
|
|
serves_gnocchi = models.BooleanField()
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s the italian restaurant" % self.name
|
2006-05-02 01:31:56 +00:00
|
|
|
|
2006-08-27 13:59:47 +00:00
|
|
|
__test__ = {'API_TESTS':"""
|
2006-05-02 01:31:56 +00:00
|
|
|
# Make sure Restaurant has the right fields in the right order.
|
|
|
|
>>> [f.name for f in Restaurant._meta.fields]
|
|
|
|
['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza']
|
|
|
|
|
|
|
|
# Make sure ItalianRestaurant has the right fields in the right order.
|
|
|
|
>>> [f.name for f in ItalianRestaurant._meta.fields]
|
|
|
|
['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza', 'serves_gnocchi']
|
|
|
|
|
|
|
|
# Create a couple of Places.
|
|
|
|
>>> p1 = Place(name='Master Shakes', address='666 W. Jersey')
|
|
|
|
>>> p1.save()
|
|
|
|
>>> p2 = Place(name='Ace Hardware', address='1013 N. Ashland')
|
|
|
|
>>> p2.save()
|
|
|
|
|
|
|
|
# Test constructor for Restaurant.
|
|
|
|
>>> r = Restaurant(name='Demon Dogs', address='944 W. Fullerton', serves_hot_dogs=True, serves_pizza=False)
|
|
|
|
>>> r.save()
|
|
|
|
|
|
|
|
# Test the constructor for ItalianRestaurant.
|
|
|
|
>>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True)
|
|
|
|
>>> ir.save()
|
|
|
|
|
|
|
|
|
2006-08-27 13:59:47 +00:00
|
|
|
"""}
|