def get_exact_match(model_class, m2m_field, ids):
    query = model_class.objects.annotate(count=Count(m2m_field)).filter(count
        =len(ids))
for _id in ids:
    pass
How to do many-to-many Django query to find book with 2 given authors?