Created
August 7, 2014 12:47
-
-
Save barseghyanartur/bfa00e351bbfea7a7a16 to your computer and use it in GitHub Desktop.
Sync Django permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://djangosnippets.org/snippets/2398/ | |
from django.core.management.base import BaseCommand | |
from django.db.models import get_models, get_app | |
from django.contrib.auth.management import create_permissions | |
class Command(BaseCommand): | |
args = '<app app ...>' | |
help = 'reloads permissions for specified apps, or all apps if no args are specified' | |
def handle(self, *args, **options): | |
if not args: | |
apps = [] | |
for model in get_models(): | |
apps.append(get_app(model._meta.app_label)) | |
else: | |
apps = [] | |
for arg in args: | |
apps.append(get_app(arg)) | |
for app in apps: | |
create_permissions(app, get_models(), options.get('verbosity', 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment