Ticket #10159: geowherenode_expressions_fix.diff

File geowherenode_expressions_fix.diff, 1.7 KB (added by jbronn, 15 years ago)
  • django/contrib/gis/db/models/sql/where.py

     
    11import datetime
     2from django.db import connection
    23from django.db.models.fields import Field
     4from django.db.models.sql.expressions import SQLEvaluator
    35from django.db.models.sql.where import WhereNode
    46from django.contrib.gis.db.backend import get_geo_where_clause, SpatialBackend
     7qn = connection.ops.quote_name
    58
    69class GeoAnnotation(object):
    710    """
     
    3740            # Not a geographic field, so call `WhereNode.add`.
    3841            return super(GeoWhereNode, self).add(data, connector)
    3942        else:
    40             # `GeometryField.get_db_prep_lookup` returns a where clause
    41             # substitution array in addition to the parameters.
    42             where, params = field.get_db_prep_lookup(lookup_type, value)
    4343
     44            if isinstance(value, SQLEvaluator):
     45                # If an expression is used, we are getting a database column so
     46                # we we don't send to get_db_prep_lookup.
     47                where =  ['%s.%s' % tuple(map(qn, value.cols[value.expression]))]
     48                params = ()
     49            else:
     50                # `GeometryField.get_db_prep_lookup` returns a where clause
     51                # substitution array in addition to the parameters.
     52                where, params = field.get_db_prep_lookup(lookup_type, value)
     53
    4454            # The annotation will be a `GeoAnnotation` object that
    4555            # will contain the necessary geometry field metadata for
    4656            # the `get_geo_where_clause` to construct the appropriate
Back to Top