Evaluating Django Chained QuerySets Locally

Posted by jnadro52 on Stack Overflow See other posts from Stack Overflow or by jnadro52
Published on 2010-03-29T21:23:22Z Indexed on 2010/03/29 21:33 UTC
Read the original article Hit count: 304

Filed under:
|

Hello All:

I am hoping someone can help me out with a quick question I have regarding chaining Django querysets. I am noticing a slow down because I am evaluating many data points in the database to create data trends. I was wondering if there was a way to have the chained filters evaluated locally instead of hitting the database. Here is a (crude) example:

pastries = Bakery.objects.filter(productType='pastry') # <--- will obviously always hit DB, when evaluated
cannoli = pastries.filter(specificType='cannoli') # <--- can this be evaluated locally instead of hitting the DB when evaluated, as long as pastries was evaluated?

I have checked the docs and I do not see anything specifying this, so I guess it's not possible, but I wanted to check with the 'braintrust' first ;-).

BTW - I know that I can do this myself by implementing some methods to loop through these datapoints and evaluate the criteria, but there are so many datapoints that my deadline does not permit me manually implementing this.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-queryset