I’d like to count the number of items returned in my queryset. For example
userdesigns = Design.objects.filter (desadder = user.id)
I’d like to get the number of object returned without using count().
The reason is that I’m trying to speed up performance and reduce the number of database queries that I perform and I noticed that using count() pings the database, which I don’t want. Considering I already pulled the complete lets of userdesigns, shouldn’t there be a way to just count the number of items stored in that returned queryset?
Source
So, if you call
len(userdesigns)instead ofuserdesigns.count(), django will request all related data from the table in a single query. After that you can access all items ofuserdesignsvariable, no additional queries will be made.