6👍
✅
Queryset is not a list of result objects. It is a lazily evaluated objects that runs its query when you first try to read its content. But when you print it from the console its output is same as list of objects. So most people think them as simple lists.
At the second example you are converting your queryset to a list. Thats why it works. You could also do
foo = list(Foo.objects.annotate(bar_count=Count('bar')).filter(bar_count__gte=1))
And it would work too.
If you won’t need them as Foo objects later on. I suggest to use values or values_list operator. Which will give faster results and smaller memory footprint. ( http://www.yilmazhuseyin.com/blog/dev/django-orm-performance-tips-part-2/ )
Source:stackexchange.com