Re: testing foo_set existence for each object in a queryset

2011-02-20 Thread Dan
Hi Lior, Thanks for the effort - but I'm not sure it can be done this way. The problem is the related model is not accessible at the level of MyModel - only at the level of its instances (if I'm saying that correctly). So if I try something like that I get the error message: "Cannot resolve

Re: testing foo_set existence for each object in a queryset

2011-02-20 Thread Dan
Thanks Shawn That's helpful. I was actually looking at the manager documentation today thinking perhaps that was what I needed - but couldn't quite wrap my head around it. But knowing that it indeed is the way to go will no doubt provide the motivation I need. (I have problems learning

Re: testing foo_set existence for each object in a queryset

2011-02-19 Thread Lior Sion
Dan, If I understand your question correctly, you are struggling with creating the filtering you wrote in your message on the queryset level (without going to the db for each object), right? Hard to say without actually seeing your code and testing, but would this be the same?

Re: testing foo_set existence for each object in a queryset

2011-02-19 Thread Shawn Milochik
Not only is it not a stupid question, but it's one of the best possible types of questions. Any time someone comes in and makes it obvious that they've thought about their problem and made an attempt to solve it themselves, they get my respect. The easiest answer to your question is to make a

testing foo_set existence for each object in a queryset

2011-02-19 Thread Dan
Hi, Long time lurker - first time poster - hopefully future answerer... Basically what I want to do can be done with: result = [w for w in MyModel.objects.all() if w.foo_set.filter(endtime__gt = datetime.datetime.now()).exists()] Is there anyway to do this using the queryset api? Hopefully