code: def _get_m2m_field(model, sender):
      
      for field in getattr(model, '_tracked_fields', []):
          if isinstance(model._meta.get_field(field), ManyToManyField):
              if getattr(model, field).through == sender:
                  return field
      for field in getattr(model, '_tracked_related_fields', {}).keys():
          if isinstance(model._meta.get_field(field), ManyToManyField):
              if getattr(model, field).through == sender:
                  return field
docs: Get the field name from a model and a sender from m2m_changed signal.