PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/model_inheritance_regress/models.py

https://code.google.com/p/mango-py/
Python | 165 lines | 111 code | 48 blank | 6 comment | 0 complexity | 45346cfd11d9e526eb91c53cf2f57174 MD5 | raw file
  1import datetime
  2
  3from django.db import models
  4
  5class Place(models.Model):
  6    name = models.CharField(max_length=50)
  7    address = models.CharField(max_length=80)
  8
  9    class Meta:
 10        ordering = ('name',)
 11
 12    def __unicode__(self):
 13        return u"%s the place" % self.name
 14
 15class Restaurant(Place):
 16    serves_hot_dogs = models.BooleanField()
 17    serves_pizza = models.BooleanField()
 18
 19    def __unicode__(self):
 20        return u"%s the restaurant" % self.name
 21
 22class ItalianRestaurant(Restaurant):
 23    serves_gnocchi = models.BooleanField()
 24
 25    def __unicode__(self):
 26        return u"%s the italian restaurant" % self.name
 27
 28class 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()
 32
 33    def __unicode__(self):
 34        return u"%s the parking lot" % self.name
 35
 36class 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)
 40
 41class 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)
 45
 46class Supplier(models.Model):
 47    restaurant = models.ForeignKey(Restaurant)
 48
 49class Wholesaler(Supplier):
 50    retailer = models.ForeignKey(Supplier,related_name='wholesale_supplier')
 51
 52class Parent(models.Model):
 53    created = models.DateTimeField(default=datetime.datetime.now)
 54
 55class Child(Parent):
 56    name = models.CharField(max_length=10)
 57
 58class SelfRefParent(models.Model):
 59    parent_data = models.IntegerField()
 60    self_data = models.ForeignKey('self', null=True)
 61
 62class SelfRefChild(SelfRefParent):
 63    child_data = models.IntegerField()
 64
 65class Article(models.Model):
 66    headline = models.CharField(max_length=100)
 67    pub_date = models.DateTimeField()
 68    class Meta:
 69        ordering = ('-pub_date', 'headline')
 70
 71    def __unicode__(self):
 72        return self.headline
 73
 74class ArticleWithAuthor(Article):
 75    author = models.CharField(max_length=100)
 76
 77class M2MBase(models.Model):
 78    articles = models.ManyToManyField(Article)
 79
 80class M2MChild(M2MBase):
 81    name = models.CharField(max_length=50)
 82
 83class Evaluation(Article):
 84    quality = models.IntegerField()
 85
 86    class Meta:
 87        abstract = True
 88
 89class QualityControl(Evaluation):
 90    assignee = models.CharField(max_length=50)
 91
 92class BaseM(models.Model):
 93    base_name = models.CharField(max_length=100)
 94
 95    def __unicode__(self):
 96        return self.base_name
 97
 98class DerivedM(BaseM):
 99    customPK = models.IntegerField(primary_key=True)
100    derived_name = models.CharField(max_length=100)
101
102    def __unicode__(self):
103        return "PK = %d, base_name = %s, derived_name = %s" \
104                % (self.customPK, self.base_name, self.derived_name)
105
106class AuditBase(models.Model):
107    planned_date = models.DateField()
108
109    class Meta:
110        abstract = True
111        verbose_name_plural = u'Audits'
112
113class CertificationAudit(AuditBase):
114    class Meta(AuditBase.Meta):
115        abstract = True
116
117class InternalCertificationAudit(CertificationAudit):
118    auditing_dept = models.CharField(max_length=20)
119
120# Check that abstract classes don't get m2m tables autocreated.
121class Person(models.Model):
122    name = models.CharField(max_length=100)
123
124    class Meta:
125        ordering = ('name',)
126
127    def __unicode__(self):
128        return self.name
129
130class AbstractEvent(models.Model):
131    name = models.CharField(max_length=100)
132    attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
133
134    class Meta:
135        abstract = True
136        ordering = ('name',)
137
138    def __unicode__(self):
139        return self.name
140
141class BirthdayParty(AbstractEvent):
142    pass
143
144class BachelorParty(AbstractEvent):
145    pass
146
147class MessyBachelorParty(BachelorParty):
148    pass
149
150# Check concrete -> abstract -> concrete inheritance
151class SearchableLocation(models.Model):
152    keywords = models.CharField(max_length=256)
153
154class Station(SearchableLocation):
155    name = models.CharField(max_length=128)
156
157    class Meta:
158        abstract = True
159
160class BusStation(Station):
161    bus_routes = models.CommaSeparatedIntegerField(max_length=128)
162    inbound = models.BooleanField()
163
164class TrainStation(Station):
165    zone = models.IntegerField()