#SQL equivalents: SELECT ... WHERE id IN (1, 3, 4); SELECT ... WHERE headline IN ('a', 'b', 'c'); #You can also use a queryset to dynamically evaluate the list of values instead of providing a list of literal values: inner_qs = Blog.objects.filter(name__contains='Cheddar') entries = Entry.objects.filter(blog__in=inner_qs)
Here is what the above code is Doing:
1. The inner query, Blog.objects.filter(name__contains=’Cheddar’), is executed and its results are used to construct the IN clause of the outer query.
2. The outer query, Entry.objects.filter(blog__in=inner_qs), is executed.