How can I selectively override a django .count() method

Posted by Tom Viner on Stack Overflow See other posts from Stack Overflow or by Tom Viner
Published on 2010-04-28T03:11:45Z Indexed on 2010/04/28 6:33 UTC
Read the original article Hit count: 247

Filed under:
|
|

I'm using postGresSQL and my main table has about 20,000 rows. Sometimes count() methods can take ages or even timeout.

Mod.manager.filter(...).count()

I need to selectively override the count() method depending on what filter has been applied.

Just having a cache of results would be a great gain but I'd like to be able to say: if filter query is just {'enabled'=True} then return 20,000 without touching the db.

Note: I can't prevent the call to .count() as it's inside django's pagination, which always does a count.

© Stack Overflow or respective owner

Related posts about django

Related posts about postgresql