本文整理汇总了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
示例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
示例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
示例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)
示例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
示例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"
)
示例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"
)
示例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
示例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)
示例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)