Q:

What's the best way to check if a queryset is a subset of another?

If there are two querysets q1 and q2, what's the best way to check if q1 is a subset of q2 ? Or do I have to iterate the values of them ?
q1_id = q1.values_list('id', flat=True)
q2_id = q2.values_list('id', flat=True)
all([x in q2 for x in q1])

A:

You could use set to check this:
q1_id = set(q1.values_list('id', flat=True)
q2_id = set(q2.values_list('id', flat=True)
issubset = q1_id.issubset(q2_id)

