为了应对一个场景:线上项目,新增功能之后,手动创建新增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-----
微信公众号:Python程序员杂谈
微信公众号:Python程序员杂谈