PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. from django.db import models
  2. class Building(models.Model):
  3. name = models.CharField(max_length=10)
  4. def __unicode__(self):
  5. return u"Building: %s" % self.name
  6. class Device(models.Model):
  7. building = models.ForeignKey('Building')
  8. name = models.CharField(max_length=10)
  9. def __unicode__(self):
  10. return u"device '%s' in building %s" % (self.name, self.building)
  11. class Port(models.Model):
  12. device = models.ForeignKey('Device')
  13. port_number = models.CharField(max_length=10)
  14. def __unicode__(self):
  15. return u"%s/%s" % (self.device.name, self.port_number)
  16. class Connection(models.Model):
  17. start = models.ForeignKey(Port, related_name='connection_start',
  18. unique=True)
  19. end = models.ForeignKey(Port, related_name='connection_end', unique=True)
  20. def __unicode__(self):
  21. return u"%s to %s" % (self.start, self.end)
  22. # Another non-tree hierarchy that exercises code paths similar to the above
  23. # example, but in a slightly different configuration.
  24. class TUser(models.Model):
  25. name = models.CharField(max_length=200)
  26. class Person(models.Model):
  27. user = models.ForeignKey(TUser, unique=True)
  28. class Organizer(models.Model):
  29. person = models.ForeignKey(Person)
  30. class Student(models.Model):
  31. person = models.ForeignKey(Person)
  32. class Class(models.Model):
  33. org = models.ForeignKey(Organizer)
  34. class Enrollment(models.Model):
  35. std = models.ForeignKey(Student)
  36. cls = models.ForeignKey(Class)
  37. # Models for testing bug #8036.
  38. class Country(models.Model):
  39. name = models.CharField(max_length=50)
  40. class State(models.Model):
  41. name = models.CharField(max_length=50)
  42. country = models.ForeignKey(Country)
  43. class ClientStatus(models.Model):
  44. name = models.CharField(max_length=50)
  45. class Client(models.Model):
  46. name = models.CharField(max_length=50)
  47. state = models.ForeignKey(State, null=True)
  48. status = models.ForeignKey(ClientStatus)
  49. class SpecialClient(Client):
  50. value = models.IntegerField()
  51. # Some model inheritance exercises
  52. class Parent(models.Model):
  53. name = models.CharField(max_length=10)
  54. def __unicode__(self):
  55. return self.name
  56. class Child(Parent):
  57. value = models.IntegerField()
  58. class Item(models.Model):
  59. name = models.CharField(max_length=10)
  60. child = models.ForeignKey(Child, null=True)
  61. def __unicode__(self):
  62. return self.name