diff --git a/tests/modeltests/select_related/models.py b/tests/modeltests/select_related/models.py
index 3c2e772..ef0d3e4 100644
a
|
b
|
class Species(models.Model):
|
56 | 56 | name = models.CharField(max_length=50) |
57 | 57 | genus = models.ForeignKey(Genus) |
58 | 58 | def __unicode__(self): |
59 | | return self.name |
60 | | No newline at end of file |
| 59 | return self.name |
| 60 | |
| 61 | class Parent1(models.Model): |
| 62 | name = models.CharField(max_length=50) |
| 63 | def __unicode__(self): |
| 64 | return self.name |
| 65 | |
| 66 | class Parent2(models.Model): |
| 67 | subname = models.CharField(max_length=50) |
| 68 | def __unicode__(self): |
| 69 | return self.subname |
| 70 | |
| 71 | class Child1(Parent2): |
| 72 | parent1 = models.OneToOneField(Parent1) |
| 73 | def __unicode__(self): |
| 74 | return self.subname |
diff --git a/tests/modeltests/select_related/tests.py b/tests/modeltests/select_related/tests.py
index 1b3715a..adc8351 100644
a
|
b
|
from __future__ import with_statement, absolute_import
|
2 | 2 | |
3 | 3 | from django.test import TestCase |
4 | 4 | |
5 | | from .models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species |
| 5 | from .models import (Domain, Kingdom, Phylum, Klass, Order, Family, Genus, |
| 6 | Species, Parent1, Child1) |
6 | 7 | |
7 | 8 | |
8 | 9 | class SelectRelatedTests(TestCase): |
… |
… |
class SelectRelatedTests(TestCase):
|
31 | 32 | self.create_tree("Eukaryota Animalia Chordata Mammalia Primates Hominidae Homo sapiens") |
32 | 33 | self.create_tree("Eukaryota Plantae Magnoliophyta Magnoliopsida Fabales Fabaceae Pisum sativum") |
33 | 34 | self.create_tree("Eukaryota Fungi Basidiomycota Homobasidiomycatae Agaricales Amanitacae Amanita muscaria") |
| 35 | parent = Parent1(name="Parent1") |
| 36 | parent.save() |
| 37 | child = Child1(subname="Child1", parent1=parent) |
| 38 | child.save() |
34 | 39 | |
35 | 40 | def setUp(self): |
36 | 41 | # The test runner sets settings.DEBUG to False, but we want to gather |
… |
… |
class SelectRelatedTests(TestCase):
|
160 | 165 | Species.objects.select_related, |
161 | 166 | 'genus__family__order', depth=4 |
162 | 167 | ) |
| 168 | |
| 169 | def test_subclass_with_select_related(self): |
| 170 | with self.assertNumQueries(1): |
| 171 | p = Parent1.objects.select_related('child1').get(name="Parent1") |
| 172 | self.assertEqual(p.child1.subname, u'Child1') |
| 173 | |
| 174 | def test_subclass_without_select_related(self): |
| 175 | with self.assertNumQueries(2): |
| 176 | p = Parent1.objects.get(name="Parent1") |
| 177 | self.assertEqual(p.child1.subname, u'Child1') |