Hello, I have defined two models, one reffered from another with ManyToManyField.
This referrer is used to categorising objects with 0, 1 or more tags. Now I want to get all objects, which have set tag "food" *and* *have not* set tag "cake". Example: object | tags -------+---------- obj1 | food, meat obj2 | food, meat obj3 | food obj4 | food, cake obj5 | food, cake obj6 | food, vegetable obj7 | garden, vegetable This get all objects with tag="food" set (obj1..obj5): Obj.objects.filter(tags__in=[Tags.objects.filter(name='food')]) This get all objects, which haven't set tag "cake" (obj1..obj3, obj6..obj7): Obj.objects.exclude(tags__in=[Tags.objects.filter(name='cake')]) When I try to combine DB queries together, I don't get what I expect (obj1..obj3, obj6): Obj.objects.filter(tags__in=[Tags.objects.filter(name='food')]).objects.exclude(tags__in=[Tags.objects.filter(name='cake')]) How to construct queries like this please? Regards Michal --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---