25

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?

ekad
  • 14,436
  • 26
  • 44
  • 46
icn
  • 17,126
  • 39
  • 105
  • 141

3 Answers3

36

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

g.user_set.remove(your_user)
phoenix
  • 7,988
  • 6
  • 39
  • 45
TigorC
  • 534
  • 1
  • 6
  • 11
17

The simplest method to clear all user groups from the user object is

user_obj.groups.clear()
Shihabudheen K M
  • 1,347
  • 1
  • 13
  • 19
15

To remove a specific Group:

group = Group.objects.get(name='groupname') 
user.groups.remove(group)
maxsocl
  • 484
  • 3
  • 9