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 keyword 'foo_set' into field. Choices are: ..." You did give me an idea though... MyModel.objects.filter(foo__endtime__gt = datetime.datetime.now()).distinct() This seems to work. Dammit - there goes my motivation to learn about managers. :) Actually - that's the same as "SELECT DISTINCT" in sql - so is perhaps not very efficient... That should provide a bit of a motivation boost at least. Thanks for the help. On Feb 20, 5:00 pm, Lior Sion <lior.s...@gmail.com> wrote: > 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? > > MyModel.objects.filter(foo_set__endtime__gt == > datetime.datetime.now()) > > I don't think you'll need the exists, as only existing objects will > come back from the query. > > On Feb 20, 3:50 am, Dan <danhaggar...@gmail.com> wrote: > > > > > > > > > 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 it's not too stupid a question... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.