Login

Custom Command for Rebuilding Permissions and ContentTypes

Author:
cronosa
Posted:
March 21, 2011
Language:
Python
Version:
Not specified
Tags:
permission permissions management command
Score:
2 (after 2 ratings)

Add this to any app as a custom management command.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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))
    

More like this

  1. Management command to list custom management commands by pbx 5 years, 9 months ago
  2. Clean spam from comments by running management command and akismet by iElectric 2 years, 5 months ago
  3. Management command which helps to find temlate files by skyjur 4 years, 2 months ago
  4. syncdata command by graham 6 years, 8 months ago
  5. reset_db management command by dnordberg 6 years, 9 months ago

Comments

cronosa (on March 21, 2011):

Added this to the django-extensions on a fork: https://github.com/gdoermann/django-extensions

#

Please login first before commenting.