code: def _members_changed(
          sender, instance, action, reverse, model, pk_set, **kwargs):
      
      if action == "post_remove":
          if not reverse:
              group = instance
              for person in model.objects.filter(pk__in=pk_set):
                  _remove_group(group, person)
          else:
              person = instance
              for group in model.objects.filter(pk__in=pk_set):
                  _remove_group(group, person)
  
      elif action == "pre_clear":
          # This has to occur in pre_clear, not post_clear, as otherwise
          # we won't see what groups need to be removed.
          if not reverse:
              group = instance
              for person in group.members.all():
                  _remove_group(group, person)
          else:
              person = instance
              for group in person.groups.all():
                  _remove_group(group, person)
docs: Hook that executes whenever the group members are changed.