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. Edit the account and remove all rights except one Permission, then the user is no longer a Super User and can be deleted.
Django does provide groups and permissions option but this is a model or table level and not at the object level. Hence we decided on creating groups based on the objects on which we want to provide the access and the users were added to these groups as per requirement or based on the existing state of an object.
See documentation https://docs.djangoproject.com/en/stable/topics/auth/#methods
g.user_set.remove(your_user)
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