2012-06-07 18:08:47 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2008-06-29 04:36:18 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 23:34:56 +02:00
|
|
|
|
2008-06-29 04:36:18 +02:00
|
|
|
class Building(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "Building: %s" % self.name
|
2008-06-29 04:36:18 +02:00
|
|
|
|
|
|
|
class Device(models.Model):
|
|
|
|
building = models.ForeignKey('Building')
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "device '%s' in building %s" % (self.name, self.building)
|
2008-06-29 04:36:18 +02:00
|
|
|
|
|
|
|
class Port(models.Model):
|
|
|
|
device = models.ForeignKey('Device')
|
2008-07-02 18:59:17 +02:00
|
|
|
port_number = models.CharField(max_length=10)
|
2008-06-29 04:36:18 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "%s/%s" % (self.device.name, self.port_number)
|
2008-06-29 04:36:18 +02:00
|
|
|
|
|
|
|
class Connection(models.Model):
|
|
|
|
start = models.ForeignKey(Port, related_name='connection_start',
|
|
|
|
unique=True)
|
|
|
|
end = models.ForeignKey(Port, related_name='connection_end', unique=True)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "%s to %s" % (self.start, self.end)
|
2008-06-29 04:36:18 +02:00
|
|
|
|
2008-08-26 00:43:25 +02:00
|
|
|
# Another non-tree hierarchy that exercises code paths similar to the above
|
|
|
|
# example, but in a slightly different configuration.
|
|
|
|
class TUser(models.Model):
|
|
|
|
name = models.CharField(max_length=200)
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
user = models.ForeignKey(TUser, unique=True)
|
|
|
|
|
|
|
|
class Organizer(models.Model):
|
|
|
|
person = models.ForeignKey(Person)
|
|
|
|
|
|
|
|
class Student(models.Model):
|
|
|
|
person = models.ForeignKey(Person)
|
|
|
|
|
|
|
|
class Class(models.Model):
|
|
|
|
org = models.ForeignKey(Organizer)
|
|
|
|
|
|
|
|
class Enrollment(models.Model):
|
|
|
|
std = models.ForeignKey(Student)
|
|
|
|
cls = models.ForeignKey(Class)
|
|
|
|
|
2008-08-26 22:44:20 +02:00
|
|
|
# Models for testing bug #8036.
|
|
|
|
class Country(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
country = models.ForeignKey(Country)
|
|
|
|
|
|
|
|
class ClientStatus(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
class Client(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
state = models.ForeignKey(State, null=True)
|
|
|
|
status = models.ForeignKey(ClientStatus)
|
|
|
|
|
2010-04-30 16:07:47 +02:00
|
|
|
class SpecialClient(Client):
|
|
|
|
value = models.IntegerField()
|
|
|
|
|
2009-03-24 04:59:38 +01:00
|
|
|
# Some model inheritance exercises
|
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Child(Parent):
|
|
|
|
value = models.IntegerField()
|
|
|
|
|
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
child = models.ForeignKey(Child, null=True)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|