How To Delete a User From a Group From an Action

Overview

This article will show you how to remove a User from a Group programmatically without having to manually remove them in the UI.

Example

This action below is an example of manually setting the UserProfile and Group, but could also be passed into the action and pulled from the kwargs.

from accounts.models import Group, GroupRoleMembership, UserProfile

def run(**kwargs):
    user_profile = UserProfile.objects.get(id=00)
    group = Group.objects.get(id=00)
    GroupRoleMembership.objects.filter(profile=user_profile,group=group).delete()

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.