Django how to remove a user from a group
-
19-06-2021 - |
Pregunta
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?
Solución
See documentation https://docs.djangoproject.com/en/stable/topics/auth/#methods
g.user_set.remove(your_user)
Otros consejos
The simplest method to clear all user groups from the user object is
user_obj.groups.clear()
To remove a specific Group:
group = Group.objects.get(name='groupname')
user.groups.remove(group)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow