summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-12-06 01:52:14 +0000
committerJustin Bronn <jbronn@gmail.com>2008-12-06 01:52:14 +0000
commit4058429708da7380385a28959ba10a51cda7f05a (patch)
tree7215fcee08291e59248e98ce1d80da4760881f5c
parent8370e7ca876f305c88863aa84f624b01d6add04e (diff)
Fixed #9572 -- use `opts` argument. Thanks SeanL for bug report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9572 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/db/models/sql/query.py2
-rw-r--r--django/contrib/gis/tests/relatedapp/models.py9
-rw-r--r--django/contrib/gis/tests/relatedapp/tests.py7
3 files changed, 16 insertions, 2 deletions
diff --git a/django/contrib/gis/db/models/sql/query.py b/django/contrib/gis/db/models/sql/query.py
index 92c26fa126..52f521d500 100644
--- a/django/contrib/gis/db/models/sql/query.py
+++ b/django/contrib/gis/db/models/sql/query.py
@@ -122,7 +122,7 @@ class GeoQuery(sql.Query):
table_alias = start_alias
else:
table_alias = self.tables[0]
- root_pk = self.model._meta.pk.column
+ root_pk = opts.pk.column
seen = {None: table_alias}
aliases = set()
for field, model in opts.get_fields_with_model():
diff --git a/django/contrib/gis/tests/relatedapp/models.py b/django/contrib/gis/tests/relatedapp/models.py
index ff4beb4647..5db6baa1f3 100644
--- a/django/contrib/gis/tests/relatedapp/models.py
+++ b/django/contrib/gis/tests/relatedapp/models.py
@@ -11,3 +11,12 @@ class City(models.Model):
state = USStateField()
location = models.ForeignKey(Location)
objects = models.GeoManager()
+
+class AugmentedLocation(Location):
+ extra_text = models.TextField(blank=True)
+ objects = models.GeoManager()
+
+class DirectoryEntry(models.Model):
+ listing_text = models.CharField(max_length=50)
+ location = models.ForeignKey(AugmentedLocation)
+ objects = models.GeoManager()
diff --git a/django/contrib/gis/tests/relatedapp/tests.py b/django/contrib/gis/tests/relatedapp/tests.py
index 5fe63cbc8e..47d49c73e9 100644
--- a/django/contrib/gis/tests/relatedapp/tests.py
+++ b/django/contrib/gis/tests/relatedapp/tests.py
@@ -2,7 +2,7 @@ import os, unittest
from django.contrib.gis.geos import *
from django.contrib.gis.tests.utils import no_mysql, postgis
from django.conf import settings
-from models import City, Location
+from models import City, Location, DirectoryEntry
cities = (('Aurora', 'TX', -97.516111, 33.058333),
('Roswell', 'NM', -104.528056, 33.387222),
@@ -89,6 +89,11 @@ class RelatedGeoModelTest(unittest.TestCase):
u2 = City.objects.exclude(name='Roswell').unionagg(field_name='location__point')
self.assertEqual(ref_u1, u1)
self.assertEqual(ref_u2, u2)
+
+ def test05_select_related_fk_to_subclass(self):
+ "Testing that calling select_related on a query over a model with an FK to a model subclass works"
+ # Regression test for #9752.
+ l = list(DirectoryEntry.objects.all().select_related())
# TODO: Related tests for KML, GML, and distance lookups.