Aggregation over a few models - Django

Posted by RadiantHex on Stack Overflow See other posts from Stack Overflow or by RadiantHex
Published on 2010-03-20T03:52:23Z Indexed on 2010/03/20 4:11 UTC
Read the original article Hit count: 176

Filed under:
|
|
|

Hi folks,

I'm trying to compute the average of a field over various subsets of a queryset.

Player.objects.order_by('-score').filter(sex='male').aggregate(Avg('level'))

This works perfectly!

But... if I try to compute it for the top 50 players it does not work.

Player.objects.order_by('-score').filter(sex='male')[:50].aggregate(Avg('level'))

This last one returns the exact same result as the query above it, which is wrong.


What am I doing wrong?

Help would be very much appreciated!

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models