Ticket #10757: 10757.diff
File 10757.diff, 4.4 KB (added by , 16 years ago) |
---|
-
contrib/gis/db/models/sql/query.py
67 67 # This loop customized for GeoQuery. 68 68 for col, field in izip(self.select, self.select_fields): 69 69 if isinstance(col, (list, tuple)): 70 r = self.get_field_select(field, col[0] )70 r = self.get_field_select(field, col[0], col[1]) 71 71 if with_aliases: 72 72 if col[1] in col_aliases: 73 73 c_alias = 'Col%d' % len(col_aliases) … … 105 105 106 106 # This loop customized for GeoQuery. 107 107 for (table, col), field in izip(self.related_select_cols, self.related_select_fields): 108 r = self.get_field_select(field, table )108 r = self.get_field_select(field, table, col) 109 109 if with_aliases and col in col_aliases: 110 110 c_alias = 'Col%d' % len(col_aliases) 111 111 result.append('%s AS %s' % (r, c_alias)) … … 239 239 sel_fmt = sel_fmt % self.custom_select[alias] 240 240 return sel_fmt 241 241 242 def get_field_select(self, fld, alias=None ):242 def get_field_select(self, fld, alias=None, column=None): 243 243 """ 244 244 Returns the SELECT SQL string for the given field. Figures out 245 245 if any custom selection SQL is needed for the column The `alias` … … 251 251 if fld in self.custom_select: 252 252 field_sel = sel_fmt % self.custom_select[fld] 253 253 else: 254 field_sel = sel_fmt % self._field_column(fld, alias )254 field_sel = sel_fmt % self._field_column(fld, alias, column) 255 255 return field_sel 256 256 257 257 def get_select_format(self, fld): … … 281 281 return sel_fmt 282 282 283 283 # Private API utilities, subject to change. 284 def _field_column(self, field, table_alias=None ):284 def _field_column(self, field, table_alias=None, column=None): 285 285 """ 286 286 Helper function that returns the database column for the given field. 287 287 The table and column are returned (quoted) in the proper format, e.g., … … 289 289 database table associated with the model of this `GeoQuery` will be 290 290 used. 291 291 """ 292 column = column or field.column 292 293 if table_alias is None: table_alias = self.model._meta.db_table 293 294 return "%s.%s" % (self.quote_name_unless_alias(table_alias), 294 self.connection.ops.quote_name( field.column))295 self.connection.ops.quote_name(column)) 295 296 296 297 def _geo_field(self, field_name=None): 297 298 """ -
contrib/gis/tests/geoapp/tests.py
4 4 from django.contrib.gis.geos import * 5 5 from django.contrib.gis.measure import Distance 6 6 from django.contrib.gis.tests.utils import no_oracle, no_postgis, no_spatialite 7 from models import Country, City, PennsylvaniaCity, State 7 from models import Country, City, PennsylvaniaCity, State, Child 8 8 9 9 if not SpatialBackend.spatialite: 10 10 from models import Feature, MinusOneSRID … … 620 620 621 621 self.assertEqual(1, qs.count()) 622 622 for pc in qs: self.assertEqual(32128, pc.point.srid) 623 624 def test27_values(self): 625 sql = Child.objects.values('parent__id').query.as_sql()[0] 626 self.assertEqual('SELECT "geoapp_child"."parent_id" FROM "geoapp_child"', sql) 623 627 624 628 from test_feeds import GeoFeedTest 625 629 from test_regress import GeoRegressionTests -
contrib/gis/tests/geoapp/models.py
37 37 class MinusOneSRID(models.Model): 38 38 geom = models.PointField(srid=-1) # Minus one SRID. 39 39 objects = models.GeoManager() 40 41 class Parent(models.Model): 42 name = models.CharField(max_length=30) 43 objects = models.GeoManager() 44 45 class Child(models.Model): 46 name = models.CharField(max_length=30) 47 parent = models.ForeignKey(Parent, related_name='children') 48 objects = models.GeoManager() 49 No newline at end of file