Skip to content

Instantly share code, notes, and snippets.

@drinks
Last active January 10, 2022 01:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drinks/5447540 to your computer and use it in GitHub Desktop.
Save drinks/5447540 to your computer and use it in GitHub Desktop.
Regenerate permissions when they get out of sync with content types in a django project (will destroy all existing permissions) I swear there used to be a management command for this...
from django.db.models import get_apps, get_models
from django.contrib.auth.management import create_permissions
Permission.objects.all().delete()
[create_permissions(app, get_models(app), 2) for app in get_apps()]
@ratpik
Copy link

ratpik commented Oct 12, 2013

I believe the management command you are referring to is part of django_extensions

./manage.py help update_permissions
Usage: manage.py update_permissions [options] <app app ...>

reloads permissions for specified apps, or all apps if no args are specified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment