Django how to remove a user from a group

icn picture icn · Jul 8, 2012 · Viewed 14.8k times · Source

Here is the code I add a user to a group

g = Group.objects.get(name='groupname') 
g.user_set.add(your_user)

When I delete a User how I remove this user from group?

Answer

TigorC picture TigorC · Jul 8, 2012

See documentation https://docs.djangoproject.com/en/stable/topics/auth/#methods

g.user_set.remove(your_user)