Hi Florian,
That's technically correct, but the universe of all possible items might be
very large or even infinite so it's not really practical to do it that way.
Dave

On Tue, May 17, 2016 at 9:32 AM florian <florian.ira...@gmail.com> wrote:

>
>
> Le mardi 17 mai 2016 14:04:28 UTC+2, David Xiao a écrit :
>>
>> Hi Vitor,
>>
>> Sorry I realized that my example should have used a ManyToManyField
>> instead of a 1-to-many.  Let me try again:
>>
>> class Bundle(Model)
>>   items = ManyToManyField("Item")
>>
>> class Item(Model)
>>   pass
>>
>> (So one item can belong many Bundles and one Bundle can have many Items.)
>>
>> Suppose I've created items item1, item2, item3 and I have special_items =
>> [item1, item2].  Suppose also the following Bundles exist in the database:
>> 1. Bundle containing item1
>> 2. Bundle containing item2
>> 3. Bundle containing item1, item2
>> 4. Bundle containing item2, item3
>> 5. Bundle containing item1, item2, item3
>>
>> I want to select all bundles where *every item in the bundle* is in
>> special_items.  This means selecting bundles 1, 2, 3 but not bundles 4, 5
>> (because item3 is not in special_items).
>>
>> The query you gave would select no bundles, and the query
>> Bundle.objects.filter(items__in=[special_items]) would select all the
>> bundles.
>>
>> Dave
>>
>
>
> an exclude on all items that are not in special_items?
>
> exclude(items__in=[not_special_items])
>
> Florian
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/tv49fShowIQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5ecb6508-5a62-4cb3-a5bc-204ec0162483%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5ecb6508-5a62-4cb3-a5bc-204ec0162483%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH7gzDBcfxtcUAc--W52eO9uLBBWP-ZK4Akr0md6_p8AUwrC9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to