本文整理匯總了Python中django.db.models.Manager.use_for_related_fields方法的典型用法代碼示例。如果您正苦於以下問題:Python Manager.use_for_related_fields方法的具體用法?Python Manager.use_for_related_fields怎麽用?Python Manager.use_for_related_fields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models.Manager
的用法示例。
在下文中一共展示了Manager.use_for_related_fields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: manager_class
# 需要導入模塊: from django.db.models import Manager [as 別名]
# 或者: from django.db.models.Manager import use_for_related_fields [as 別名]
def manager_class(model, queryset_class=None, class_name=None,
use_for_related_fields=False):
"""
Return the manager class for model.
If an optional queryset is given, returns a new class using the
Manager.from_queryset() API.
"""
for cls in model.mro():
if not issubclass(model, Model):
continue
try:
mgm = cls.objects
break
except AttributeError:
pass
else:
mgm = Manager()
if not isinstance(mgm, BaseManager):
raise TypeError('unexpected manager class: %s' %
mgm.__class__.__name__)
if queryset_class is not None:
mgm = mgm.from_queryset(queryset_class, class_name=class_name)
if use_for_related_fields:
mgm.use_for_related_fields = True
return mgm