Thursday, March 31, 2016

Re: Q() chaining with & returns empty set

> Den 31. mar. 2016 kl. 04.14 skrev Bai Shun <>:
> I've got a problem in using Q()

To see what's going on, try to print the SQL that Django generates for working and non-working queryset:

> print Basket.objects.filter(Q(fruit__ofkind__name__in=['apple'])&Q(fruit__ofkind__name__in=['banana'])).distinct()

> Basket.objects.filter(fruit__ofkind__name__in=['apple']).filter(fruit__ofkind__name__in=['banana']).distinct()

Print SQL like this:



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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment