Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to force queryset evaluation while keeping it a queryset

Tags:

django

I would like to evaluate a queryset once, i.e. fetch the objects to local memory, and then proceed with performing various filter commands on the fetched objects.

Of course I could:

  • Drop to list comprehensions and other native python syntax, but in many case django ORM's syntax is more readable.
  • Skip evaluating the base queryset, but then I'll get a performance hit as I require quite a few filter operations later on.

So.. Is it possible to force a queryset evaluation while keeping the result as a queryset object?

like image 813
Jonathan Livni Avatar asked Dec 17 '13 09:12

Jonathan Livni


1 Answers

How about just doing a len(myqueryset).

or just doing an conditional check can also force evaluate it.

like image 174
Mevin Babu Avatar answered Sep 22 '22 13:09

Mevin Babu