2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2008-06-26 07:51:19 +00:00
|
|
|
import datetime
|
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
class Place(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
address = models.CharField(max_length=80)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
2008-06-26 07:51:19 +00:00
|
|
|
|
2008-06-09 14:03:35 +00:00
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s the place" % self.name
|
2008-06-09 14:03:35 +00:00
|
|
|
|
|
|
|
class Restaurant(Place):
|
|
|
|
serves_hot_dogs = models.BooleanField()
|
|
|
|
serves_pizza = models.BooleanField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s the restaurant" % self.name
|
2008-06-09 14:03:35 +00:00
|
|
|
|
|
|
|
class ItalianRestaurant(Restaurant):
|
|
|
|
serves_gnocchi = models.BooleanField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s the italian restaurant" % self.name
|
2008-06-09 14:03:35 +00:00
|
|
|
|
|
|
|
class ParkingLot(Place):
|
|
|
|
# An explicit link to the parent (we can control the attribute name).
|
|
|
|
parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
|
|
|
|
capacity = models.IntegerField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s the parking lot" % self.name
|
2008-06-09 14:03:35 +00:00
|
|
|
|
2009-03-04 07:21:14 +00:00
|
|
|
class ParkingLot2(Place):
|
|
|
|
# In lieu of any other connector, an existing OneToOneField will be
|
|
|
|
# promoted to the primary key.
|
|
|
|
parent = models.OneToOneField(Place)
|
|
|
|
|
|
|
|
class ParkingLot3(Place):
|
|
|
|
# The parent_link connector need not be the pk on the model.
|
|
|
|
primary_key = models.AutoField(primary_key=True)
|
|
|
|
parent = models.OneToOneField(Place, parent_link=True)
|
|
|
|
|
2008-07-23 06:12:15 +00:00
|
|
|
class Supplier(models.Model):
|
|
|
|
restaurant = models.ForeignKey(Restaurant)
|
|
|
|
|
2010-04-23 14:25:29 +00:00
|
|
|
class Wholesaler(Supplier):
|
|
|
|
retailer = models.ForeignKey(Supplier,related_name='wholesale_supplier')
|
|
|
|
|
2008-06-26 07:51:19 +00:00
|
|
|
class Parent(models.Model):
|
|
|
|
created = models.DateTimeField(default=datetime.datetime.now)
|
|
|
|
|
|
|
|
class Child(Parent):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2008-07-28 01:32:46 +00:00
|
|
|
class SelfRefParent(models.Model):
|
|
|
|
parent_data = models.IntegerField()
|
|
|
|
self_data = models.ForeignKey('self', null=True)
|
2008-07-23 06:12:15 +00:00
|
|
|
|
2008-07-28 01:32:46 +00:00
|
|
|
class SelfRefChild(SelfRefParent):
|
|
|
|
child_data = models.IntegerField()
|
2008-07-23 06:12:15 +00:00
|
|
|
|
2008-09-01 21:04:01 +00:00
|
|
|
class Article(models.Model):
|
|
|
|
headline = models.CharField(max_length=100)
|
|
|
|
pub_date = models.DateTimeField()
|
|
|
|
class Meta:
|
|
|
|
ordering = ('-pub_date', 'headline')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.headline
|
|
|
|
|
|
|
|
class ArticleWithAuthor(Article):
|
2008-09-03 05:53:50 +00:00
|
|
|
author = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class M2MBase(models.Model):
|
|
|
|
articles = models.ManyToManyField(Article)
|
|
|
|
|
|
|
|
class M2MChild(M2MBase):
|
|
|
|
name = models.CharField(max_length=50)
|
2008-09-01 21:04:01 +00:00
|
|
|
|
2008-09-03 18:38:43 +00:00
|
|
|
class Evaluation(Article):
|
|
|
|
quality = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
class QualityControl(Evaluation):
|
|
|
|
assignee = models.CharField(max_length=50)
|
|
|
|
|
2009-03-04 07:20:08 +00:00
|
|
|
class BaseM(models.Model):
|
|
|
|
base_name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.base_name
|
|
|
|
|
|
|
|
class DerivedM(BaseM):
|
|
|
|
customPK = models.IntegerField(primary_key=True)
|
|
|
|
derived_name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return "PK = %d, base_name = %s, derived_name = %s" \
|
|
|
|
% (self.customPK, self.base_name, self.derived_name)
|
2008-09-03 18:38:43 +00:00
|
|
|
|
2010-11-17 12:09:21 +00:00
|
|
|
class AuditBase(models.Model):
|
|
|
|
planned_date = models.DateField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2012-06-07 16:08:47 +00:00
|
|
|
verbose_name_plural = 'Audits'
|
2010-11-17 12:09:21 +00:00
|
|
|
|
|
|
|
class CertificationAudit(AuditBase):
|
|
|
|
class Meta(AuditBase.Meta):
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
class InternalCertificationAudit(CertificationAudit):
|
|
|
|
auditing_dept = models.CharField(max_length=20)
|
|
|
|
|
2009-11-03 14:02:49 +00:00
|
|
|
# Check that abstract classes don't get m2m tables autocreated.
|
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class AbstractEvent(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class BirthdayParty(AbstractEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class BachelorParty(AbstractEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class MessyBachelorParty(BachelorParty):
|
|
|
|
pass
|
2011-02-12 15:07:27 +00:00
|
|
|
|
|
|
|
# Check concrete -> abstract -> concrete inheritance
|
|
|
|
class SearchableLocation(models.Model):
|
|
|
|
keywords = models.CharField(max_length=256)
|
|
|
|
|
|
|
|
class Station(SearchableLocation):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
class BusStation(Station):
|
|
|
|
bus_routes = models.CommaSeparatedIntegerField(max_length=128)
|
|
|
|
inbound = models.BooleanField()
|
|
|
|
|
|
|
|
class TrainStation(Station):
|
|
|
|
zone = models.IntegerField()
|
2012-04-20 17:34:29 +00:00
|
|
|
|
|
|
|
class User(models.Model):
|
|
|
|
username = models.CharField(max_length=30, unique=True)
|
|
|
|
|
|
|
|
class Profile(User):
|
|
|
|
profile_id = models.AutoField(primary_key=True)
|
|
|
|
extra = models.CharField(max_length=30, blank=True)
|