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


Python related.RECURSIVE_RELATIONSHIP_CONSTANT属性代码示例

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


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

示例1: _get_model_tuple

# 需要导入模块: from django.db.models.fields import related [as 别名]
# 或者: from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT [as 别名]
def _get_model_tuple(self, remote_model, app_label, model_name):
        if remote_model == RECURSIVE_RELATIONSHIP_CONSTANT:
            return app_label, model_name.lower()
        elif '.' in remote_model:
            return tuple(remote_model.lower().split('.'))
        else:
            return app_label, remote_model.lower() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:9,代码来源:models.py

示例2: _find_reload_model

# 需要导入模块: from django.db.models.fields import related [as 别名]
# 或者: from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT [as 别名]
def _find_reload_model(self, app_label, model_name, delay=False):
        if delay:
            self.is_delayed = True

        related_models = set()

        try:
            old_model = self.apps.get_model(app_label, model_name)
        except LookupError:
            pass
        else:
            # Get all relations to and from the old model before reloading,
            # as _meta.apps may change
            if delay:
                related_models = get_related_models_tuples(old_model)
            else:
                related_models = get_related_models_recursive(old_model)

        # Get all outgoing references from the model to be rendered
        model_state = self.models[(app_label, model_name)]
        # Directly related models are the models pointed to by ForeignKeys,
        # OneToOneFields, and ManyToManyFields.
        direct_related_models = set()
        for name, field in model_state.fields:
            if field.is_relation:
                if field.remote_field.model == RECURSIVE_RELATIONSHIP_CONSTANT:
                    continue
                rel_app_label, rel_model_name = _get_app_label_and_model_name(field.related_model, app_label)
                direct_related_models.add((rel_app_label, rel_model_name.lower()))

        # For all direct related models recursively get all related models.
        related_models.update(direct_related_models)
        for rel_app_label, rel_model_name in direct_related_models:
            try:
                rel_model = self.apps.get_model(rel_app_label, rel_model_name)
            except LookupError:
                pass
            else:
                if delay:
                    related_models.update(get_related_models_tuples(rel_model))
                else:
                    related_models.update(get_related_models_recursive(rel_model))

        # Include the model itself
        related_models.add((app_label, model_name))

        return related_models 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:49,代码来源:state.py

示例3: reload_model

# 需要导入模块: from django.db.models.fields import related [as 别名]
# 或者: from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT [as 别名]
def reload_model(self, app_label, model_name):
        if 'apps' in self.__dict__:  # hasattr would cache the property
            try:
                old_model = self.apps.get_model(app_label, model_name)
            except LookupError:
                related_models = set()
            else:
                # Get all relations to and from the old model before reloading,
                # as _meta.apps may change
                related_models = get_related_models_recursive(old_model)

            # Get all outgoing references from the model to be rendered
            model_state = self.models[(app_label, model_name)]
            # Directly related models are the models pointed to by ForeignKeys,
            # OneToOneFields, and ManyToManyFields.
            direct_related_models = set()
            for name, field in model_state.fields:
                if field.is_relation:
                    if field.remote_field.model == RECURSIVE_RELATIONSHIP_CONSTANT:
                        continue
                    rel_app_label, rel_model_name = _get_app_label_and_model_name(field.related_model, app_label)
                    direct_related_models.add((rel_app_label, rel_model_name.lower()))

            # For all direct related models recursively get all related models.
            related_models.update(direct_related_models)
            for rel_app_label, rel_model_name in direct_related_models:
                try:
                    rel_model = self.apps.get_model(rel_app_label, rel_model_name)
                except LookupError:
                    pass
                else:
                    related_models.update(get_related_models_recursive(rel_model))

            # Include the model itself
            related_models.add((app_label, model_name))

            # Unregister all related models
            with self.apps.bulk_update():
                for rel_app_label, rel_model_name in related_models:
                    self.apps.unregister_model(rel_app_label, rel_model_name)

            states_to_be_rendered = []
            # Gather all models states of those models that will be rerendered.
            # This includes:
            # 1. All related models of unmigrated apps
            for model_state in self.apps.real_models:
                if (model_state.app_label, model_state.name_lower) in related_models:
                    states_to_be_rendered.append(model_state)

            # 2. All related models of migrated apps
            for rel_app_label, rel_model_name in related_models:
                try:
                    model_state = self.models[rel_app_label, rel_model_name]
                except KeyError:
                    pass
                else:
                    states_to_be_rendered.append(model_state)

            # Render all models
            self.apps.render_multiple(states_to_be_rendered) 
开发者ID:drexly,项目名称:openhgsenti,代码行数:62,代码来源:state.py


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