`m2m_changed` is for any many-to-many field, but it's better to specify the sender
xxxxxxxxxx
self.walrus.groups.remove(self.peon_group)
@receiver(signal=m2m_changed, sender=User.groups.through)
def adjust_group_notifications(instance, action, reverse, model, pk_set, using, *args, **kwargs):
if model == Group and not reverse:
logger.info("User %s deleted their relation to groups «%s»", instance.username, pk_set)
if action == 'post_remove':
# The *modification* happening is a deletion of the link
…
elif action == 'post_add':
logger.info("User %s created a relation to groups «%s»", instance.username, ", ".join(pk_set))
…
else:
logger.info("Group %s is modifying its relation to users «%s»", instance, pk_set)
…
return