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

/tests/regressiontests/select_related_regress/models.py

https://code.google.com/p/mango-py/
Python | 86 lines | 58 code | 24 blank | 4 comment | 0 complexity | dee52087a2adc501dc9d1c9f51e36273 MD5 | raw file
 1from django.db import models
 2
 3class Building(models.Model):
 4    name = models.CharField(max_length=10)
 5
 6    def __unicode__(self):
 7        return u"Building: %s" % self.name
 8
 9class Device(models.Model):
10    building = models.ForeignKey('Building')
11    name = models.CharField(max_length=10)
12
13    def __unicode__(self):
14        return u"device '%s' in building %s" % (self.name, self.building)
15
16class Port(models.Model):
17    device = models.ForeignKey('Device')
18    port_number = models.CharField(max_length=10)
19
20    def __unicode__(self):
21        return u"%s/%s" % (self.device.name, self.port_number)
22
23class Connection(models.Model):
24    start = models.ForeignKey(Port, related_name='connection_start',
25            unique=True)
26    end = models.ForeignKey(Port, related_name='connection_end', unique=True)
27
28    def __unicode__(self):
29        return u"%s to %s" % (self.start, self.end)
30
31# Another non-tree hierarchy that exercises code paths similar to the above
32# example, but in a slightly different configuration.
33class TUser(models.Model):
34    name = models.CharField(max_length=200)
35
36class Person(models.Model):
37    user = models.ForeignKey(TUser, unique=True)
38
39class Organizer(models.Model):
40    person = models.ForeignKey(Person)
41
42class Student(models.Model):
43    person = models.ForeignKey(Person)
44
45class Class(models.Model):
46    org = models.ForeignKey(Organizer)
47
48class Enrollment(models.Model):
49    std = models.ForeignKey(Student)
50    cls = models.ForeignKey(Class)
51
52# Models for testing bug #8036.
53class Country(models.Model):
54    name = models.CharField(max_length=50)
55
56class State(models.Model):
57    name = models.CharField(max_length=50)
58    country = models.ForeignKey(Country)
59
60class ClientStatus(models.Model):
61    name = models.CharField(max_length=50)
62
63class Client(models.Model):
64    name = models.CharField(max_length=50)
65    state = models.ForeignKey(State, null=True)
66    status = models.ForeignKey(ClientStatus)
67
68class SpecialClient(Client):
69    value = models.IntegerField()
70
71# Some model inheritance exercises
72class Parent(models.Model):
73    name = models.CharField(max_length=10)
74
75    def __unicode__(self):
76        return self.name
77
78class Child(Parent):
79    value = models.IntegerField()
80
81class Item(models.Model):
82    name = models.CharField(max_length=10)
83    child = models.ForeignKey(Child, null=True)
84
85    def __unicode__(self):
86        return self.name