summaryrefslogtreecommitdiff
path: root/tests/modeltests/model_inheritance/models.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-05-02 01:31:56 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-05-02 01:31:56 +0000
commitf69cf70ed813a8cd7e1f963a14ae39103e8d5265 (patch)
treed3b32e84cd66573b3833ddf662af020f8ef2f7a8 /tests/modeltests/model_inheritance/models.py
parentd5dbeaa9be359a4c794885c2e9f1b5a7e5e51fb8 (diff)
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2809 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/model_inheritance/models.py')
-rw-r--r--tests/modeltests/model_inheritance/models.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/modeltests/model_inheritance/models.py b/tests/modeltests/model_inheritance/models.py
new file mode 100644
index 0000000000..cdc4b4e2ac
--- /dev/null
+++ b/tests/modeltests/model_inheritance/models.py
@@ -0,0 +1,52 @@
+"""
+XX. Model inheritance
+
+"""
+
+from django.db import models
+
+class Place(models.Model):
+ name = models.CharField(maxlength=50)
+ address = models.CharField(maxlength=80)
+
+ def __repr__(self):
+ return "%s the place" % self.name
+
+class Restaurant(Place):
+ serves_hot_dogs = models.BooleanField()
+ serves_pizza = models.BooleanField()
+
+ def __repr__(self):
+ return "%s the restaurant" % self.name
+
+class ItalianRestaurant(Restaurant):
+ serves_gnocchi = models.BooleanField()
+
+ def __repr__(self):
+ return "%s the italian restaurant" % self.name
+
+API_TESTS = """
+# 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()
+
+
+"""