2008-06-29 10:36:18 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2008-06-29 10:36:18 +08:00
|
|
|
class Building(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-29 10:36:18 +08:00
|
|
|
class Device(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
building = models.ForeignKey('Building', models.CASCADE)
|
2008-06-29 10:36:18 +08:00
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-29 10:36:18 +08:00
|
|
|
class Port(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
device = models.ForeignKey('Device', models.CASCADE)
|
2008-07-03 00:59:17 +08:00
|
|
|
port_number = models.CharField(max_length=10)
|
2008-06-29 10:36:18 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s/%s" % (self.device.name, self.port_number)
|
2008-06-29 10:36:18 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-06-29 10:36:18 +08:00
|
|
|
class Connection(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
start = models.ForeignKey(
|
|
|
|
Port,
|
|
|
|
models.CASCADE,
|
|
|
|
related_name='connection_start',
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
end = models.ForeignKey(
|
|
|
|
Port,
|
|
|
|
models.CASCADE,
|
|
|
|
related_name='connection_end',
|
|
|
|
unique=True,
|
|
|
|
)
|
2008-06-29 10:36:18 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
# Another non-tree hierarchy that exercises code paths similar to the above
|
|
|
|
# example, but in a slightly different configuration.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class TUser(models.Model):
|
|
|
|
name = models.CharField(max_length=200)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class Person(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
user = models.ForeignKey(TUser, models.CASCADE, unique=True)
|
2008-08-26 06:43:25 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class Organizer(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
person = models.ForeignKey(Person, models.CASCADE)
|
2008-08-26 06:43:25 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class Student(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
person = models.ForeignKey(Person, models.CASCADE)
|
2008-08-26 06:43:25 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class Class(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
org = models.ForeignKey(Organizer, models.CASCADE)
|
2008-08-26 06:43:25 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-26 06:43:25 +08:00
|
|
|
class Enrollment(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
std = models.ForeignKey(Student, models.CASCADE)
|
|
|
|
cls = models.ForeignKey(Class, models.CASCADE)
|
2008-08-26 06:43:25 +08:00
|
|
|
|
2008-08-27 04:44:20 +08:00
|
|
|
# Models for testing bug #8036.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2008-08-27 04:44:20 +08:00
|
|
|
class Country(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-27 04:44:20 +08:00
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 22:43:21 +08:00
|
|
|
country = models.ForeignKey(Country, models.CASCADE)
|
2008-08-27 04:44:20 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-27 04:44:20 +08:00
|
|
|
class ClientStatus(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2008-08-27 04:44:20 +08:00
|
|
|
class Client(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
2015-07-22 22:43:21 +08:00
|
|
|
state = models.ForeignKey(State, models.SET_NULL, null=True)
|
|
|
|
status = models.ForeignKey(ClientStatus, models.CASCADE)
|
2008-08-27 04:44:20 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2010-04-30 22:07:47 +08:00
|
|
|
class SpecialClient(Client):
|
|
|
|
value = models.IntegerField()
|
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
# Some model inheritance exercises
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class Child(Parent):
|
|
|
|
value = models.IntegerField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2009-03-24 11:59:38 +08:00
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
2015-07-22 22:43:21 +08:00
|
|
|
child = models.ForeignKey(Child, models.SET_NULL, null=True)
|
2009-03-24 11:59:38 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-24 11:59:38 +08:00
|
|
|
return self.name
|
2013-02-21 17:12:08 +08:00
|
|
|
|
|
|
|
# Models for testing bug #19870.
|
2013-11-03 05:34:05 +08:00
|
|
|
|
|
|
|
|
2013-02-21 17:12:08 +08:00
|
|
|
class Fowl(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-21 17:12:08 +08:00
|
|
|
class Hen(Fowl):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-02-21 17:12:08 +08:00
|
|
|
class Chick(Fowl):
|
2015-07-22 22:43:21 +08:00
|
|
|
mother = models.ForeignKey(Hen, models.CASCADE)
|
2013-10-02 00:27:20 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-10-02 00:27:20 +08:00
|
|
|
class Base(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
lots_of_text = models.TextField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-10-02 00:27:20 +08:00
|
|
|
class A(Base):
|
|
|
|
a_field = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-10-02 00:27:20 +08:00
|
|
|
class B(Base):
|
|
|
|
b_field = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2013-10-02 00:27:20 +08:00
|
|
|
class C(Base):
|
2015-07-22 22:43:21 +08:00
|
|
|
c_a = models.ForeignKey(A, models.CASCADE)
|
|
|
|
c_b = models.ForeignKey(B, models.CASCADE)
|
2013-10-02 01:26:19 +08:00
|
|
|
is_published = models.BooleanField(default=False)
|