def get_m2m(parent_model, model):
    """
    Returns ManyToManyField field.
    """
    # need to check on both sides (m2m field will be defined only in one of the
    # models)
    for rel in parent_model._meta.get_all_related_many_to_many_objects():
        if issubclass(rel.related_model, model):
            return rel.field

    for rel in parent_model._meta.many_to_many:
        if issubclass(rel.related_model, model):
            return rel.field