Ticket #10757: 10757.diff

File 10757.diff, 4.4 KB (added by David Gouldin, 15 years ago)
  • contrib/gis/db/models/sql/query.py

     
    6767            # This loop customized for GeoQuery.
    6868            for col, field in izip(self.select, self.select_fields):
    6969                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])
    7171                    if with_aliases:
    7272                        if col[1] in col_aliases:
    7373                            c_alias = 'Col%d' % len(col_aliases)
     
    105105
    106106        # This loop customized for GeoQuery.
    107107        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)
    109109            if with_aliases and col in col_aliases:
    110110                c_alias = 'Col%d' % len(col_aliases)
    111111                result.append('%s AS %s' % (r, c_alias))
     
    239239            sel_fmt = sel_fmt % self.custom_select[alias]
    240240        return sel_fmt
    241241
    242     def get_field_select(self, fld, alias=None):
     242    def get_field_select(self, fld, alias=None, column=None):
    243243        """
    244244        Returns the SELECT SQL string for the given field.  Figures out
    245245        if any custom selection SQL is needed for the column  The `alias`
     
    251251        if fld in self.custom_select:
    252252            field_sel = sel_fmt % self.custom_select[fld]
    253253        else:
    254             field_sel = sel_fmt % self._field_column(fld, alias)
     254            field_sel = sel_fmt % self._field_column(fld, alias, column)
    255255        return field_sel
    256256
    257257    def get_select_format(self, fld):
     
    281281        return sel_fmt
    282282
    283283    # 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):
    285285        """
    286286        Helper function that returns the database column for the given field.
    287287        The table and column are returned (quoted) in the proper format, e.g.,
     
    289289        database table associated with the model of this `GeoQuery` will be
    290290        used.
    291291        """
     292        column = column or field.column
    292293        if table_alias is None: table_alias = self.model._meta.db_table
    293294        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))
    295296
    296297    def _geo_field(self, field_name=None):
    297298        """
  • contrib/gis/tests/geoapp/tests.py

     
    44from django.contrib.gis.geos import *
    55from django.contrib.gis.measure import Distance
    66from django.contrib.gis.tests.utils import no_oracle, no_postgis, no_spatialite
    7 from models import Country, City, PennsylvaniaCity, State
     7from models import Country, City, PennsylvaniaCity, State, Child
    88
    99if not SpatialBackend.spatialite:
    1010    from models import Feature, MinusOneSRID
     
    620620
    621621        self.assertEqual(1, qs.count())
    622622        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)
    623627
    624628from test_feeds import GeoFeedTest
    625629from test_regress import GeoRegressionTests
  • contrib/gis/tests/geoapp/models.py

     
    3737    class MinusOneSRID(models.Model):
    3838        geom = models.PointField(srid=-1) # Minus one SRID.
    3939        objects = models.GeoManager()
     40
     41class Parent(models.Model):
     42    name = models.CharField(max_length=30)
     43    objects = models.GeoManager()
     44
     45class 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
Back to Top