Doing a count over a filter query efficiently in django

Posted by apple_pie on Stack Overflow See other posts from Stack Overflow or by apple_pie
Published on 2010-05-25T08:23:16Z Indexed on 2010/05/25 8:31 UTC
Read the original article Hit count: 217

Filed under:
|
|

Hello, Django newbie here, I need to do a count over a certain filter in a django model. If I do it like so: my_model.objects.filter(...).count() I'm guessing it does the SQL query that retrieves all the rows and only afterwards does the count. To my knowledge it's much more efficient to do the count without retrieving those rows like so "SELECT COUNT(*) FROM ...". Is there a way to do so in django?

© Stack Overflow or respective owner

Related posts about python

Related posts about django