本文整理汇总了Python中django.apps.apps.get_containing_app_config方法的典型用法代码示例。如果您正苦于以下问题:Python apps.get_containing_app_config方法的具体用法?Python apps.get_containing_app_config怎么用?Python apps.get_containing_app_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.apps.apps
的用法示例。
在下文中一共展示了apps.get_containing_app_config方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: app
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def app(self):
return apps.get_containing_app_config(type(self).__module__).name
示例2: type_def
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def type_def(self, type_def):
if isinstance(type_def, str):
type_def = import_string(type_def)
if not issubclass(type_def, self.type_def_subclass):
raise TypeError('type_def must be a subclass of {}'.format(self.type_def_subclass))
# Import meta options from type_def
with suppress(AttributeError):
self.type_name = type_def.Meta.db_type
with suppress(AttributeError):
self.type_app_label = type_def.Meta.app_label
if not self.type_app_label:
# Determine app_label of enum being used
app_config = apps.get_containing_app_config(type_def.__module__)
if app_config is None:
raise RuntimeError(
"type_def class doesn't declare an explicit app_label, and isn't"
" in an application in INSTALLED_APPS")
self.type_app_label = app_config.label
# Generate type_name if not already set
if not self.type_name:
self.type_name = '{app_label}_{type_subclass}_{type_name}'.format(
app_label=self.type_app_label,
type_subclass=self.type_def_subclass.__name__.lower(),
type_name=type_def.__qualname__.lower())
self._type_def = type_def
示例3: app
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def app(self) -> str:
return apps.get_containing_app_config(type(self).__module__).name
示例4: __init__
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def __init__(self, report):
self._report = report
module = self._report.__class__.__module__
app_config = apps.get_containing_app_config(module)
self._app_label = app_config.label
self._object_name = self._report.__class__.__name__
示例5: get_urls
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def get_urls(self):
urlpatterns = []
for report in self._registry:
app_name = apps.get_containing_app_config(report.__module__).name
urlpatterns.append(
url(r"^{0}/{1}/$".format(app_name.replace(".", "_"), report.__name__.lower()),
admin_site.admin_view(ReportView.as_view(report_class=report)),
name=camel_re.sub(r'\1_\2', report.__name__).lower()
))
return urlpatterns
示例6: test_get_containing_app_config_apps_not_ready
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def test_get_containing_app_config_apps_not_ready(self):
"""
apps.get_containing_app_config() should raise an exception if
apps.apps_ready isn't True.
"""
apps.apps_ready = False
try:
with self.assertRaisesMessage(AppRegistryNotReady, "Apps aren't loaded yet"):
apps.get_containing_app_config('foo')
finally:
apps.apps_ready = True
示例7: _add_django_meta_and_register_model
# 需要导入模块: from django.apps import apps [as 别名]
# 或者: from django.apps.apps import get_containing_app_config [as 别名]
def _add_django_meta_and_register_model(cls, klass, attrs, name):
# Create the class.
module = attrs.get('__module__')
if not module:
return klass
new_class = klass
attr_meta = attrs.pop('Meta', None)
abstract = getattr(attr_meta, 'abstract', False)
if not attr_meta:
meta = getattr(new_class, 'Meta', None)
else:
meta = attr_meta
if meta:
meta.managed = False
app_label = None
# Look for an application configuration to attach the model to.
app_config = apps.get_containing_app_config(module)
if getattr(meta, 'app_label', None) is None:
if app_config is None:
if not abstract:
raise RuntimeError(
"Model class %s.%s doesn't declare an explicit "
"app_label and isn't in an application in "
"INSTALLED_APPS." % (module, name)
)
else:
app_label = app_config.label
# Add _meta/Options attribute to the model
new_class.add_to_class(
'_meta', DjangoCassandraOptions(meta, app_label, cls=new_class))
# Add manager to the model
for manager_attr in _django_manager_attr_names:
new_class.add_to_class(manager_attr, new_class.objects)
# Register the model
new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
return new_class