本文整理汇总了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
示例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')
示例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")
示例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