Re: Dynamic OR statements

2009-01-06 Thread Bluemilkshake
That looks great Alex, thanks a lot. Also being a Python noob I wasn't aware you could chain together operators in that way. (I assumed, like C# you could only use += or -=, but |= is very cool). Surrounded by geniuses...I love it! -M On Jan 5, 5:09 pm, "alex.gay...@gmail.com" wrote: > You need

Re: Dynamic OR statements

2009-01-05 Thread bruno desthuilliers
On 5 jan, 18:09, "alex.gay...@gmail.com" wrote: > You need to build up the Q object and then filter on it so: > results = RelatedModel.objects.all() > q = Q() > for category in category_list: > q |= Q(categories__slug = category.slug) > results = results.filter(q) Or create a sequence of Q

Re: Dynamic OR statements

2009-01-05 Thread Enrico
Hi Mark, I think you could use the Q object like this: q_filter = Q() for category in category_list: q_filter = q_filter | Q(categories__slug=category.slug) results = RelatedModel.objects.filter(q_filter) Best regards, Enrico --~--~-~--~~~---~--~~ You receive

Re: Dynamic OR statements

2009-01-05 Thread alex.gay...@gmail.com
You need to build up the Q object and then filter on it so: results = RelatedModel.objects.all() q = Q() for category in category_list: q |= Q(categories__slug = category.slug) results = results.filter(q) On Jan 5, 10:52 am, Bluemilkshake wrote: > Hello. Django noob here, pretty much. > > I

Re: Dynamic OR statements

2009-01-05 Thread Ronny Haryanto
On Mon, Jan 5, 2009 at 11:59 PM, Ronny Haryanto wrote: > On Mon, Jan 5, 2009 at 11:52 PM, Bluemilkshake > wrote: >> for category in category_list: >>results = results.filter(categories__slug = category.slug) > > How about results.filter(category__in=category_list)? Whoops. Never mind. Repli

Re: Dynamic OR statements

2009-01-05 Thread Ronny Haryanto
On Mon, Jan 5, 2009 at 11:52 PM, Bluemilkshake wrote: > for category in category_list: >results = results.filter(categories__slug = category.slug) How about results.filter(category__in=category_list)? Ronny --~--~-~--~~~---~--~~ You received this message bec

Dynamic OR statements

2009-01-05 Thread Bluemilkshake
Hello. Django noob here, pretty much. I understand how one can use Q objects to construct OR statements within a QuerySet, but (how) is it possible to do this dynamically? I have a list of categories, and I want to find items that match ANY of those categories. The current solution doesn't work