(permissions)
迁移时新增权限
迁移时新增权限
迁移时新增权限
def upgrade_perms(permissions):
    """迁移时新增权限"""
    with transaction.atomic():
        content_type = ContentType.objects.get_for_model(WeChatApp)
        apps = WeChatApp.objects.all()
        for app in apps:
            for perm_name in get_perm_names(app, permissions):
                query = dict(
                    codename=perm_name,
                    content_type=content_type
                )
                defaults = query.copy()
                defaults.update(dict(name=get_perm_desc(perm_name, app)))
                Permission.objects.update_or_create(
                    defaults=defaults, **query)
def upgrade_perms ( permissions ) : with transaction . atomic ( ) : content_type = ContentType . objects . get_for_model ( WeChatApp ) apps = WeChatApp . objects . all ( ) for app in apps : for perm_name in get_perm_names ( app , permissions ) : query = dict ( codename = perm_name , content_type = content_type ) defaults = query . copy ( ) defaults . update ( dict ( name = get_perm_desc ( perm_name , app ) ) ) Permission . objects . update_or_create ( defaults = defaults , * * query )