web/lib/django/contrib/gis/db/models/aggregates.py
changeset 0 0d40e90630ef
child 29 cc9b7e14412b
equal deleted inserted replaced
-1:000000000000 0:0d40e90630ef
       
     1 from django.db.models import Aggregate
       
     2 from django.contrib.gis.db.backend import SpatialBackend
       
     3 from django.contrib.gis.db.models.sql import GeomField
       
     4 
       
     5 class GeoAggregate(Aggregate):
       
     6 
       
     7     def add_to_query(self, query, alias, col, source, is_summary):
       
     8         if hasattr(source, 'geom_type'):
       
     9             # Doing additional setup on the Query object for spatial aggregates.
       
    10             aggregate = getattr(query.aggregates_module, self.name)
       
    11             
       
    12             # Adding a conversion class instance and any selection wrapping
       
    13             # SQL (e.g., needed by Oracle).
       
    14             if aggregate.conversion_class is GeomField:
       
    15                 query.extra_select_fields[alias] = GeomField()
       
    16                 if SpatialBackend.select:
       
    17                     query.custom_select[alias] = SpatialBackend.select
       
    18      
       
    19         super(GeoAggregate, self).add_to_query(query, alias, col, source, is_summary)
       
    20 
       
    21 class Collect(GeoAggregate):
       
    22     name = 'Collect'
       
    23 
       
    24 class Extent(GeoAggregate):
       
    25     name = 'Extent'
       
    26 
       
    27 class MakeLine(GeoAggregate):
       
    28     name = 'MakeLine'
       
    29 
       
    30 class Union(GeoAggregate):
       
    31     name = 'Union'