5👍
How about just doing a len(myqueryset)
.
or just doing an conditional check can also force evaluate it.
2👍
You can’t keep queryset object when you force it. But you can do something like this:
In : list(Project.objects.values_list('owner', 'owner__email'))
Out: [(1, 'admin@example.com')]
So, use values_list to keep data that you’ll use.
Greetings.
- Docker + Django + Postgres Add-on + Heroku
- Set global minimum logging level across all loggers in Python/Django
- Django – disable one of system checks
1👍
You can easily force an evaluation by iterating the queryset: as long as you ignore the result of the iteration, your object stays a queryset.
for item in myqueryset:
pass
However this won’t really do what you want, since you say you want to call further filter methods on the evaluated queryset. This can’t work, since filter()
involves modifying the underlying query, and will always hit the database.
I don’t know why you think you’ll get a performance hit if you skip evaluating the queryset though: the opposite is the case, your proposed evaluation is the unnecessary step.
- Multiple default values specified for column "id" of the table
- Django-registration – how do i change example.com in the email?
- How to add data-attribute to django modelform modelchoicefield