PageRenderTime 243ms CodeModel.GetById 141ms app.highlight 5ms RepoModel.GetById 95ms 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
 1"""
 241. Tests for select_related()
 3
 4``select_related()`` follows all relationships and pre-caches any foreign key
 5values so that complex trees can be fetched in a single query. However, this
 6isn't always a good idea, so the ``depth`` argument control how many "levels"
 7the select-related behavior will traverse.
 8"""
 9
10from django.db import models
11
12# Who remembers high school biology?
13
14class Domain(models.Model):
15    name = models.CharField(max_length=50)
16    def __unicode__(self):
17        return self.name
18
19class Kingdom(models.Model):
20    name = models.CharField(max_length=50)
21    domain = models.ForeignKey(Domain)
22    def __unicode__(self):
23        return self.name
24
25class Phylum(models.Model):
26    name = models.CharField(max_length=50)
27    kingdom = models.ForeignKey(Kingdom)
28    def __unicode__(self):
29        return self.name
30
31class Klass(models.Model):
32    name = models.CharField(max_length=50)
33    phylum = models.ForeignKey(Phylum)
34    def __unicode__(self):
35        return self.name
36
37class Order(models.Model):
38    name = models.CharField(max_length=50)
39    klass = models.ForeignKey(Klass)
40    def __unicode__(self):
41        return self.name
42
43class Family(models.Model):
44    name = models.CharField(max_length=50)
45    order = models.ForeignKey(Order)
46    def __unicode__(self):
47        return self.name
48
49class Genus(models.Model):
50    name = models.CharField(max_length=50)
51    family = models.ForeignKey(Family)
52    def __unicode__(self):
53        return self.name
54
55class Species(models.Model):
56    name = models.CharField(max_length=50)
57    genus = models.ForeignKey(Genus)
58    def __unicode__(self):
59        return self.name