1
0
mirror of https://github.com/django/django.git synced 2024-12-26 11:06:07 +00:00
django/tests/regressiontests/select_related_regress/models.py
Claude Paroz 4a103086d5 Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and
Jannis Leidel for the review.
2012-06-07 18:08:47 +02:00

90 lines
2.4 KiB
Python

from __future__ import unicode_literals
from django.db import models
class Building(models.Model):
name = models.CharField(max_length=10)
def __unicode__(self):
return "Building: %s" % self.name
class Device(models.Model):
building = models.ForeignKey('Building')
name = models.CharField(max_length=10)
def __unicode__(self):
return "device '%s' in building %s" % (self.name, self.building)
class Port(models.Model):
device = models.ForeignKey('Device')
port_number = models.CharField(max_length=10)
def __unicode__(self):
return "%s/%s" % (self.device.name, self.port_number)
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):
return "%s to %s" % (self.start, self.end)
# 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)
# 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)
class SpecialClient(Client):
value = models.IntegerField()
# 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