Search code examples
djangopermissions

How to remove all permissions from a group in Django


In Django authentication permissions, how to remove all permissions granted to a group?


Solution

  • There are separate ways to do this.

    • via admin

      • edit your group and simply remove all permissions enter image description here
    • via database

      DELETE FROM auth_group_permissions WHERE group_id=<id>;
      
    • via shell

      $ python manage.py shell
      
      >>> from django.contrib.auth.models import Group
      >>> group = Group.objects.get(id=<id>)
      >>> group.permissions.clear()
      

    Edit: .clear() makes more sense than .all().delete(), thx Ivan ;)