3 from django
.db
import models
5 class Place(models
.Model
):
6 name
= models
.CharField(max_length
=50)
7 address
= models
.CharField(max_length
=80)
12 def __unicode__(self
):
13 return u
"%s the place" % self
.name
15 class Restaurant(Place
):
16 serves_hot_dogs
= models
.BooleanField()
17 serves_pizza
= models
.BooleanField()
19 def __unicode__(self
):
20 return u
"%s the restaurant" % self
.name
22 class ItalianRestaurant(Restaurant
):
23 serves_gnocchi
= models
.BooleanField()
25 def __unicode__(self
):
26 return u
"%s the italian restaurant" % self
.name
28 class ParkingLot(Place
):
29 # An explicit link to the parent (we can control the attribute name).
30 parent
= models
.OneToOneField(Place
, primary_key
=True, parent_link
=True)
31 capacity
= models
.IntegerField()
33 def __unicode__(self
):
34 return u
"%s the parking lot" % self
.name
36 class ParkingLot2(Place
):
37 # In lieu of any other connector, an existing OneToOneField will be
38 # promoted to the primary key.
39 parent
= models
.OneToOneField(Place
)
41 class ParkingLot3(Place
):
42 # The parent_link connector need not be the pk on the model.
43 primary_key
= models
.AutoField(primary_key
=True)
44 parent
= models
.OneToOneField(Place
, parent_link
=True)
46 class Supplier(models
.Model
):
47 restaurant
= models
.ForeignKey(Restaurant
)
49 class Wholesaler(Supplier
):
50 retailer
= models
.ForeignKey(Supplier
,related_name
='wholesale_supplier')
52 class Parent(models
.Model
):
53 created
= models
.DateTimeField(default
=datetime
.datetime
.now
)
56 name
= models
.CharField(max_length
=10)
58 class SelfRefParent(models
.Model
):
59 parent_data
= models
.IntegerField()
60 self_data
= models
.ForeignKey('self', null
=True)
62 class SelfRefChild(SelfRefParent
):
63 child_data
= models
.IntegerField()
65 class Article(models
.Model
):
66 headline
= models
.CharField(max_length
=100)
67 pub_date
= models
.DateTimeField()
69 ordering
= ('-pub_date', 'headline')
71 def __unicode__(self
):
74 class ArticleWithAuthor(Article
):
75 author
= models
.CharField(max_length
=100)
77 class M2MBase(models
.Model
):
78 articles
= models
.ManyToManyField(Article
)
80 class M2MChild(M2MBase
):
81 name
= models
.CharField(max_length
=50)
83 class Evaluation(Article
):
84 quality
= models
.IntegerField()
89 class QualityControl(Evaluation
):
90 assignee
= models
.CharField(max_length
=50)
92 class BaseM(models
.Model
):
93 base_name
= models
.CharField(max_length
=100)
95 def __unicode__(self
):
98 class DerivedM(BaseM
):
99 customPK
= models
.IntegerField(primary_key
=True)
100 derived_name
= models
.CharField(max_length
=100)
102 def __unicode__(self
):
103 return "PK = %d, base_name = %s, derived_name = %s" \
104 % (self
.customPK
, self
.base_name
, self
.derived_name
)
106 class AuditBase(models
.Model
):
107 planned_date
= models
.DateField()
111 verbose_name_plural
= u
'Audits'
113 class CertificationAudit(AuditBase
):
114 class Meta(AuditBase
.Meta
):
117 class InternalCertificationAudit(CertificationAudit
):
118 auditing_dept
= models
.CharField(max_length
=20)
120 # Check that abstract classes don't get m2m tables autocreated.
121 class Person(models
.Model
):
122 name
= models
.CharField(max_length
=100)
127 def __unicode__(self
):
130 class AbstractEvent(models
.Model
):
131 name
= models
.CharField(max_length
=100)
132 attendees
= models
.ManyToManyField(Person
, related_name
="%(class)s_set")
138 def __unicode__(self
):
141 class BirthdayParty(AbstractEvent
):
144 class BachelorParty(AbstractEvent
):
147 class MessyBachelorParty(BachelorParty
):