Pergunta

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?

Foi útil?

Solução

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

g.user_set.remove(your_user)

Outras dicas

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top