PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/select_related/models.py

https://code.google.com/p/mango-py/
Python | 59 lines | 2 code | 0 blank | 57 comment | 0 complexity | 186996e5b87902844b5b2ba482bffc0c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. 41. Tests for select_related()
  3. ``select_related()`` follows all relationships and pre-caches any foreign key
  4. values so that complex trees can be fetched in a single query. However, this
  5. isn't always a good idea, so the ``depth`` argument control how many "levels"
  6. the select-related behavior will traverse.
  7. """
  8. from django.db import models
  9. # Who remembers high school biology?
  10. class Domain(models.Model):
  11. name = models.CharField(max_length=50)
  12. def __unicode__(self):
  13. return self.name
  14. class Kingdom(models.Model):
  15. name = models.CharField(max_length=50)
  16. domain = models.ForeignKey(Domain)
  17. def __unicode__(self):
  18. return self.name
  19. class Phylum(models.Model):
  20. name = models.CharField(max_length=50)
  21. kingdom = models.ForeignKey(Kingdom)
  22. def __unicode__(self):
  23. return self.name
  24. class Klass(models.Model):
  25. name = models.CharField(max_length=50)
  26. phylum = models.ForeignKey(Phylum)
  27. def __unicode__(self):
  28. return self.name
  29. class Order(models.Model):
  30. name = models.CharField(max_length=50)
  31. klass = models.ForeignKey(Klass)
  32. def __unicode__(self):
  33. return self.name
  34. class Family(models.Model):
  35. name = models.CharField(max_length=50)
  36. order = models.ForeignKey(Order)
  37. def __unicode__(self):
  38. return self.name
  39. class Genus(models.Model):
  40. name = models.CharField(max_length=50)
  41. family = models.ForeignKey(Family)
  42. def __unicode__(self):
  43. return self.name
  44. class Species(models.Model):
  45. name = models.CharField(max_length=50)
  46. genus = models.ForeignKey(Genus)
  47. def __unicode__(self):
  48. return self.name