I want to remove a user from all the groups that is assigned to. I am using the standard auth app in Django.
So far I am able to delete one group at a time with:
user.groups.remove(group)
but this adds a lot of sql overhead. I understand that this is an many-to-many relation, but I am not able to find which model represents the many to many mapping and call the delete method from there.
I would like to execute the following query with the Django ORM:
delete from auth_user_group where user_id = 123
I don't know what is the SQL, but you can use the clear
method:
user.groups.clear()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With