def _setup_aggregate_query(self, aggregates):
        opts = self.model._meta
        if self.query.group_by is None:
            field_names = [f.attname for f in opts.fields]
            self.query.add_fields(field_names, False)
            self.query.set_group_by()
Add object caching
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/query.py/QuerySet._setup_aggregate_query--crossover with--dataset/ETHPy150Open funkybob/django-nap/nap/rest/cache.py/CachedSerialiser.object_deflate