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


Python Manager.model方法代码示例

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


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

示例1: base_manager

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import model [as 别名]
    def base_manager(self):
        base_manager_name = self.base_manager_name
        if not base_manager_name:
            # Get the first parent's base_manager_name if there's one.
            for parent in self.model.mro()[1:]:
                if hasattr(parent, '_meta'):
                    if parent._base_manager.name != '_base_manager':
                        base_manager_name = parent._base_manager.name
                    break

        if base_manager_name:
            try:
                return self.managers_map[base_manager_name]
            except KeyError:
                raise ValueError(
                    "%s has no manager named %r" % (
                        self.object_name,
                        base_manager_name,
                    )
                )

        manager = Manager()
        manager.name = '_base_manager'
        manager.model = self.model
        manager.auto_created = True
        return manager
开发者ID:agmond,项目名称:django,代码行数:28,代码来源:options.py

示例2: base_manager

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import model [as 别名]
    def base_manager(self):
        base_manager_name = self.base_manager_name
        if not base_manager_name:
            # Get the first parent's base_manager_name if there's one.
            for parent in self.model.mro()[1:]:
                if hasattr(parent, '_meta'):
                    if parent._base_manager.name != '_base_manager':
                        base_manager_name = parent._base_manager.name
                    break

        if base_manager_name:
            try:
                return self.managers_map[base_manager_name]
            except KeyError:
                raise ValueError(
                    "%s has no manager named %r" % (
                        self.object_name,
                        base_manager_name,
                    )
                )

        # Deprecation shim for `use_for_related_fields`.
        for i, base_manager_class in enumerate(self.default_manager.__class__.mro()):
            if getattr(base_manager_class, 'use_for_related_fields', False):
                if not getattr(base_manager_class, 'silence_use_for_related_fields_deprecation', False):
                    warnings.warn(
                        "use_for_related_fields is deprecated, instead "
                        "set Meta.base_manager_name on '{}'.".format(self.model._meta.label),
                        RemovedInDjango20Warning, 2
                    )

                if i == 0:
                    manager = self.default_manager
                else:
                    manager = base_manager_class()
                    manager.name = '_base_manager'
                    manager.model = self.model

                return manager

        manager = Manager()
        manager.name = '_base_manager'
        manager.model = self.model
        manager.auto_created = True
        return manager
开发者ID:AMontagu,项目名称:django,代码行数:47,代码来源:options.py


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