the5fire的技术博客

关注python、vim、linux、web开发和互联网--life is short, we need python.


django手动同步权限节点脚本

作者:the5fire | 标签:       | 发布:2017-12-08 10:25 p.m. | 阅读量: 3498, 1241

为了应对一个场景:线上项目,新增功能之后,手动创建新增app models的权限。

# coding:utf-8
from django.apps import apps
from django.core.management.base import BaseCommand
from django.contrib.auth.management import create_permissions
class Command(BaseCommand):
    def handle(self, *args, **options):
        if not args:
            return
        app_name = args[0]
        app = apps.get_app_config(app_name)
        create_permissions(app)

保存为`sync_permissions.py到某个app的management/commands下,使用方法:

./manage.py sync_permission app名称
- from the5fire.com
----EOF-----

微信公众号:码农悟凡


其他分类: