0001_initial.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:LIMS-Backend 作者: LeafLIMS 项目源码 文件源码
def make_groups(apps, schema_editor):
    # Create the default set of user groups and
    # assign the correct permissions.

    # Permissions aren't created until after all migrations
    # are run so lets create them now!
    app_configs = apps.get_app_configs()
    for app in app_configs:
        app.models_module = True
        create_permissions(app, verbosity=0)
        app.models_module = None

    Group = apps.get_model('auth', 'Group')
    Permission = apps.get_model('auth', 'Permission')

    for group in settings.DEFAULT_GROUPS:
        g,created = Group.objects.get_or_create(name=group)
        if group == 'admin':
            # Assign all available permissions to the admin group
            p = list(Permission.objects.all())
            g.permissions.add(*p)
        elif group == 'staff':
            for perm in settings.DEFAULT_STAFF_PERMISSIONS:
                p = Permission.objects.get(name=perm)
                g.permissions.add(p)
        elif group == 'user':
            # Default permissions for users are store in
            # the settings.py file
            for perm in settings.DEFAULT_USER_PERMISSIONS:
                p = Permission.objects.get(name=perm)
                g.permissions.add(p)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号