Ticket #21096: distance-name.diff

File distance-name.diff, 2.9 KB (added by Simon Litchfield, 11 years ago)
  • django/contrib/gis/db/models/query.py

    diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py
    index c89912b..989cb16 100644
    a b class GeoQuerySet(QuerySet):  
    8585        """
    8686        return self._geomset_attribute('difference', geom, **kwargs)
    8787
    88     def distance(self, geom, **kwargs):
     88    def distance(self, geom, att='distance', **kwargs):
    8989        """
    9090        Returns the distance from the given geographic field name to the
    91         given geometry in a `distance` attribute on each element of the
    92         GeoQuerySet.
     91        given geometry in an attribute named `att` on each element of the
     92        GeoQuerySet, `distance` by default.
    9393
    9494        Keyword Arguments:
    95          `spheroid`  => If the geometry field is geodetic and PostGIS is
    96                         the spatial database, then the more accurate
    97                         spheroid calculation will be used instead of the
    98                         quicker sphere calculation.
     95         `spheroid`   => If the geometry field is geodetic and PostGIS is
     96                         the spatial database, then the more accurate
     97                         spheroid calculation will be used instead of the
     98                         quicker sphere calculation.
     99 
     100         `tolerance`  => Used only for Oracle. The tolerance is
     101                         in meters -- a default of 5 centimeters (0.05)
     102                         is used.
    99103
    100          `tolerance` => Used only for Oracle. The tolerance is
    101                         in meters -- a default of 5 centimeters (0.05)
    102                         is used.
     104         `field_name` => Explicitly set the geometry field name, by default
     105                         it uses the first it finds on the model
    103106        """
    104         return self._distance_attribute('distance', geom, **kwargs)
     107        return self._distance_attribute('distance', geom, att=att, **kwargs)
    105108
    106109    def envelope(self, **kwargs):
    107110        """
    class GeoQuerySet(QuerySet):  
    573576        return self.extra(select={model_att : fmt % settings['procedure_args']},
    574577                          select_params=settings['select_params'])
    575578
    576     def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, **kwargs):
     579    def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, att=None, **kwargs):
    577580        """
    578581        DRY routine for GeoQuerySet distance attribute routines.
    579582        """
    class GeoQuerySet(QuerySet):  
    716719            # The geometry is passed in as a parameter because we handled
    717720            # transformation conditions in this routine.
    718721            s['select_params'] = [backend.Adapter(geom)]
    719         return self._spatial_attribute(func, s, **kwargs)
     722        return self._spatial_attribute(att or func, s, **kwargs)
    720723
    721724    def _geom_attribute(self, func, tolerance=0.05, **kwargs):
    722725        """
Back to Top