相关疑难解决方法(0)

Django 1.7数据迁移和用户组

我正在尝试使用django 1.7本机迁移系统实现数据迁移.这就是我所做的.

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations


def create_basic_user_group(apps, schema_editor):
    """Forward data migration that create the basic_user group

    """
    Group = apps.get_model('auth', 'Group')
    Permission = apps.get_model('auth', 'Permission')
    group = Group(name='basic_user')
    group.save()

    perm_codenames = (
        'add_stuff',
        '...',
    )

    # we prefere looping over all these in order to be sure to fetch them all
    perms = [Permission.objects.get(codename=codename)
             for codename in perm_codenames]

    group.permissions.add(*perms)
    group.save()


def remove_basic_user_group(apps, schema_editor):
    """Backward data migration that remove the basic_user …
Run Code Online (Sandbox Code Playgroud)

python migration django

8
推荐指数
2
解决办法
1817
查看次数

标签 统计

django ×1

migration ×1

python ×1