当前位置: 首页>>代码示例>>Python>>正文


Python swapper.get_model_name方法代码示例

本文整理汇总了Python中swapper.get_model_name方法的典型用法代码示例。如果您正苦于以下问题:Python swapper.get_model_name方法的具体用法?Python swapper.get_model_name怎么用?Python swapper.get_model_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swapper的用法示例。


在下文中一共展示了swapper.get_model_name方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_default_organization_uuid

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def set_default_organization_uuid(apps, schema_editor):
    """
    Get or create a default organization then
    set settings._OPENWISP_DEFAULT_ORG_UUID
    """
    org_model = swapper.get_model_name('openwisp_users', 'organization')
    model_app_label = swapper.split(org_model)[0]
    organization = apps.get_model(model_app_label, 'organization')
    default_organization = organization.objects.first()
    if default_organization is None:
        default_organization = organization(
            name='default',
            slug='default',
            description='This is the default organization. '
            'It was created automatically during installation. '
            'You can simply rename it to your organization name.',
        )
        default_organization.full_clean()
        default_organization.save()

    # settings._OPENWISP_DEFAULT_ORG_UUID is used in
    # openwisp-radius.migrations, it helps to enable
    # users to migrate from freeradius 3
    settings._OPENWISP_DEFAULT_ORG_UUID = default_organization.pk 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:26,代码来源:__init__.py

示例2: update_admins_permissions

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def update_admins_permissions(apps, schema_editor):
    org_model = swapper.get_model_name('openwisp_users', 'organization')
    model_app_label = swapper.split(org_model)[0]
    group = apps.get_model(model_app_label, 'group')
    email_model = swapper.get_model_name('account', 'EmailAddress')
    email_app_label = swapper.split(email_model)[0]
    try:
        admin = group.objects.get(name='Administrator')
        permissions = [
            Permission.objects.get(
                content_type__app_label=email_app_label, codename='view_emailaddress'
            ).pk,
            Permission.objects.get(
                content_type__app_label=email_app_label, codename='delete_emailaddress'
            ).pk,
            Permission.objects.get(
                content_type__app_label=email_app_label, codename='change_emailaddress'
            ).pk,
            Permission.objects.get(
                content_type__app_label=model_app_label, codename='delete_user'
            ).pk,
        ]
        admin.permissions.add(*permissions)
    except ObjectDoesNotExist:
        pass 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:27,代码来源:__init__.py

示例3: add_default_menu_items

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [
            {'model': settings.AUTH_USER_MODEL},
            {'model': get_model_name('openwisp_users', 'Organization')},
        ]
        if not hasattr(settings, menu_setting):
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:13,代码来源:apps.py

示例4: get_swapped_model

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def get_swapped_model(apps, app_name, model_name):
    model_path = swapper.get_model_name(app_name, model_name)
    return get_model(apps, model_path) 
开发者ID:openwisp,项目名称:django-freeradius,代码行数:5,代码来源:__init__.py

示例5: add_default_menu_items

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [
            {'model': get_model_name('config', 'Device')},
            {'model': get_model_name('config', 'Template')},
            {'model': get_model_name('config', 'Vpn')},
        ]
        if not hasattr(settings, menu_setting):
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items 
开发者ID:openwisp,项目名称:openwisp-controller,代码行数:14,代码来源:apps.py

示例6: test_swap_setting

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def test_swap_setting(self):
        self.assertTrue(swapper.is_swapped("default_app", "Type"))
        self.assertEqual(
            swapper.get_model_name("default_app", "Type"),
            "alt_app.Type"
        ) 
开发者ID:wq,项目名称:django-swappable-models,代码行数:8,代码来源:test_swapper.py

示例7: test_default_setting

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def test_default_setting(self):
        self.assertFalse(swapper.is_swapped("default_app", "Type"))
        self.assertEqual(
            swapper.get_model_name("default_app", "Type"),
            "default_app.Type"
        ) 
开发者ID:wq,项目名称:django-swappable-models,代码行数:8,代码来源:test_swapper.py

示例8: add_default_menu_items

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def add_default_menu_items(self):
        menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS'
        items = [{'model': swapper.get_model_name('topology', 'Topology')}]
        if not hasattr(settings, menu_setting):
            setattr(settings, menu_setting, items)
        else:
            current_menu = getattr(settings, menu_setting)
            current_menu += items 
开发者ID:openwisp,项目名称:openwisp-network-topology,代码行数:10,代码来源:apps.py

示例9: get_swapped_model

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def get_swapped_model(apps, app_name, model_name):
    model_path = swapper.get_model_name(app_name, model_name)
    app, model = swapper.split(model_path)
    return apps.get_model(app, model) 
开发者ID:openwisp,项目名称:openwisp-radius,代码行数:6,代码来源:__init__.py

示例10: create_default_groups

# 需要导入模块: import swapper [as 别名]
# 或者: from swapper import get_model_name [as 别名]
def create_default_groups(apps, schema_editor):
    org_model = swapper.get_model_name('openwisp_users', 'organization')
    model_app_label = swapper.split(org_model)[0]
    group = apps.get_model(model_app_label, 'group')

    # To populate all the permissions
    for app_config in apps.get_app_configs():
        app_config.models_module = True
        create_permissions(app_config, apps=apps, verbosity=0)
        app_config.models_module = None

    operator = group.objects.filter(name='Operator')
    if operator.count() == 0:
        operator = group.objects.create(name='Operator')

    admin = group.objects.filter(name='Administrator')
    if admin.count() == 0:
        admin = group.objects.create(name='Administrator')
        permissions = [
            Permission.objects.get(
                content_type__app_label=model_app_label, codename='add_user'
            ).pk,
            Permission.objects.get(
                content_type__app_label=model_app_label, codename='change_user'
            ).pk,
            Permission.objects.get(
                content_type__app_label=model_app_label,
                codename='change_organizationuser',
            ).pk,
            Permission.objects.get(
                content_type__app_label=model_app_label,
                codename='delete_organizationuser',
            ).pk,
            Permission.objects.get(
                content_type__app_label=model_app_label,
                codename='add_organizationuser',
            ).pk,
        ]
        try:
            permissions += [
                Permission.objects.get(
                    content_type__app_label=model_app_label, codename='view_user'
                ).pk,
                Permission.objects.get(
                    content_type__app_label=model_app_label, codename='view_group'
                ).pk,
                Permission.objects.get(
                    content_type__app_label=model_app_label,
                    codename='view_organizationuser',
                ).pk,
            ]
        except Permission.DoesNotExist:
            pass
        admin.permissions.set(permissions) 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:56,代码来源:__init__.py


注:本文中的swapper.get_model_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。