[Answered ]-Django annotate to show aggregate sums and counts pre-slicing of the QuerySet

2👍

You should be able to get the queryset to evaluate by doing:

qs = list(qs)

At that point it’s no longer a queryset, just a regular Python list, which can be sliced as usual.

The problem with doing this for pagination, of course, is that no matter what page is viewed you are returning the entire set of records from the database. That could be a real problem if your dataset is large. Given your requirements it sounds like that may be unavoidable; your query either deals with all the records, or with just some of them. Without seeing more details it’s hard to know for sure.

0👍

I ended up running a separate query to get my sums, and return its result along with the actual page in question. The amount of data I’m dealing with doesn’t really allow me to work on entire query sets like that.
Thanks Carl!

👤Harel

Leave a comment