Friday, February 17, 2012

Re: QuerySet exclusion

On Feb 17, 6:33 pm, Lie Ryan <lie.1...@gmail.com> wrote:
> If I have two querysets, say 'a' and 'b', the goal is to create another
> queryset, say 'c', which has all elements in 'a' that is not in 'b'.
>
> I can write:
>
>      c = a.exclude(id__in=b.values('id'))
>
> but this seems a little tedious, why can't I just write:
>
>      c = a.exclude(b)
>
> is there any way to do similar?
>
> (note: things like `set(a) - set(b)` is not acceptable because it
> produces a python set, not a django queryset)

Yeah, it might be a little tedious, but that really isn't the most
common query. And if .exclude() accepts the syntax, one would expect
to a.filter(b) to work. That really isn't too clear...

Supporting a - b and a + b could be added, but that wouldn't be high
on my priority list. And those should be INTERSECT / UNION queries
respectively.

BTW doesn't a.exclude(id__in=b) work? IIRC it should.

- Anssi

--
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