Saturday, February 19, 2011

Re: testing foo_set existence for each object in a queryset

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate