~kkubasik/django/aggregation-branch

« back to all changes in this revision

Viewing changes to tests/modeltests/model_inheritance/models.py

  • Committer: adrian
  • Date: 2006-05-02 01:31:56 UTC
  • Revision ID: vcs-imports@canonical.com-20060502013156-2941fcd40d080649
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.

Show diffs side-by-side

added added

removed removed

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