本文整理汇总了Python中django.apps.AppConfig.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python AppConfig.__init__方法的具体用法?Python AppConfig.__init__怎么用?Python AppConfig.__init__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.apps.AppConfig
的用法示例。
在下文中一共展示了AppConfig.__init__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.apps import AppConfig [as 别名]
# 或者: from django.apps.AppConfig import __init__ [as 别名]
def __init__(self, app_label, name, fields, options=None, bases=None, managers=None):
self.app_label = app_label
self.name = force_text(name)
self.fields = fields
self.options = options or {}
self.bases = bases or (models.Model, )
self.managers = managers or []
# Sanity-check that fields is NOT a dict. It must be ordered.
if isinstance(self.fields, dict):
raise ValueError("ModelState.fields cannot be a dict - it must be a list of 2-tuples.")
# Sanity-check that fields are NOT already bound to a model.
for name, field in fields:
if hasattr(field, 'model'):
raise ValueError(
'ModelState.fields cannot be bound to a model - "%s" is.' % name
)
示例2: __init__
# 需要导入模块: from django.apps import AppConfig [as 别名]
# 或者: from django.apps.AppConfig import __init__ [as 别名]
def __init__(self, real_apps, models, ignore_swappable=False):
# Any apps in self.real_apps should have all their models included
# in the render. We don't use the original model instances as there
# are some variables that refer to the Apps object.
# FKs/M2Ms from real apps are also not included as they just
# mess things up with partial states (due to lack of dependencies)
self.real_models = []
for app_label in real_apps:
app = global_apps.get_app_config(app_label)
for model in app.get_models():
self.real_models.append(ModelState.from_model(model, exclude_rels=True))
# Populate the app registry with a stub for each application.
app_labels = {model_state.app_label for model_state in models.values()}
app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
super(StateApps, self).__init__(app_configs)
self.render_multiple(list(models.values()) + self.real_models)
# There shouldn't be any operations pending at this point.
pending_models = set(self._pending_operations)
if ignore_swappable:
pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
if pending_models:
raise ValueError(self._pending_models_error(pending_models))
示例3: __init__
# 需要导入模块: from django.apps import AppConfig [as 别名]
# 或者: from django.apps.AppConfig import __init__ [as 别名]
def __init__(self, models=None, real_apps=None):
self.models = models or {}
# Apps to include from main registry, usually unmigrated ones
self.real_apps = real_apps or []
self.is_delayed = False