for _id in ids:
    query = query.filter(**{m2m_field: _id})
return query
matches = get_exact_match(MyModel, 'my_m2m_field', [1, 2, 3, 4])
How to do many-to-many Django query to find book with 2 given authors?