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


Python Manager.name方法代码示例

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


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

示例1: base_manager

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import name [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: test_consider_real_django_fields_only

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import name [as 别名]
 def test_consider_real_django_fields_only(self):
     id_ = ModelWithImpostorField._meta.get_field('id')
     with patch.object(mommy.Mommy, 'get_fields') as mock:
         f = Manager()
         f.name = 'foo'
         mock.return_value = [id_, f]
         try:
             mommy.make(ModelWithImpostorField)
         except TypeError:
             self.fail('TypeError raised')
开发者ID:helber,项目名称:model_mommy,代码行数:12,代码来源:test_mommy.py

示例3: test_consider_real_django_fields_only

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import name [as 别名]
 def test_consider_real_django_fields_only(self):
     id_ = models.ModelWithImpostorField._meta.get_field("id")
     with patch.object(mommy.Mommy, "get_fields") as mock:
         f = Manager()
         f.name = "foo"
         mock.return_value = [id_, f]
         try:
             mommy.make(models.ModelWithImpostorField)
         except TypeError:
             self.fail("TypeError raised")
开发者ID:renatooliveira,项目名称:model_mommy,代码行数:12,代码来源:test_mommy.py

示例4: base_manager

# 需要导入模块: from django.db.models import Manager [as 别名]
# 或者: from django.db.models.Manager import name [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.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。