Ticket #15305: geoq_agg.patch
File geoq_agg.patch, 2.5 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/db/models/sql/compiler.py
171 171 """ 172 172 values = [] 173 173 aliases = self.query.extra_select.keys() 174 if self.query.aggregates:175 # If we have an aggregate annotation, must extend the aliases176 # so their corresponding row values are included.177 aliases.extend([None for i in xrange(len(self.query.aggregates))])178 174 179 175 # Have to set a starting row number offset that is used for 180 176 # determining the correct starting row index -- needed for … … 191 187 self.connection) 192 188 for v, a in izip(row[rn_offset:index_start], aliases)] 193 189 if self.connection.ops.oracle or getattr(self.query, 'geo_values', False): 190 aggregates_start = index_start + len(fields) 194 191 # We resolve the rest of the columns if we're on Oracle or if 195 192 # the `geo_values` attribute is defined. 196 for value, field in map(None, row[index_start: ], fields):193 for value, field in map(None, row[index_start:aggregates_start], fields): 197 194 values.append(self.query.convert_values(value, field, connection=self.connection)) 195 # Aggregates will be resolved by the caller via resolve_aggregate 196 values.extend(row[aggregates_start:]) 198 197 else: 199 198 values.extend(row[index_start:]) 200 199 return tuple(values) -
django/contrib/gis/tests/relatedapp/tests.py
240 240 # Count annotation should be 2 for the Dallas location now. 241 241 loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id) 242 242 self.assertEqual(2, loc.num_cities) 243 loc_q = Location.objects.annotate(num_cities=Count('city')) 244 self.assertEqual(5, len(loc_q)) 245 self.assertTrue(loc_q[0].num_cities > 0) 246 loc_qv = Location.objects.all().values('id').annotate(num_cities=Count('city')) 247 self.assertEqual(5, len(loc_qv)) 248 self.assertTrue(loc_qv[0]['num_cities'] > 0) 243 249 244 250 def test12b_count(self): 245 251 "Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087."