本文整理汇总了Python中django.db.models.manager.BaseManager.from_queryset方法的典型用法代码示例。如果您正苦于以下问题:Python BaseManager.from_queryset方法的具体用法?Python BaseManager.from_queryset怎么用?Python BaseManager.from_queryset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.manager.BaseManager
的用法示例。
在下文中一共展示了BaseManager.from_queryset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __str__
# 需要导入模块: from django.db.models.manager import BaseManager [as 别名]
# 或者: from django.db.models.manager.BaseManager import from_queryset [as 别名]
name = models.CharField(max_length=100)
slug = models.SlugField()
class Meta:
ordering = ['name']
def __str__(self):
return self.name
class DoesNotExistQuerySet(QuerySet):
def get(self, *args, **kwargs):
raise Author.DoesNotExist
DoesNotExistBookManager = BaseManager.from_queryset(DoesNotExistQuerySet)
class Book(models.Model):
name = models.CharField(max_length=300)
slug = models.SlugField()
pages = models.IntegerField()
authors = models.ManyToManyField(Author)
pubdate = models.DateField()
objects = models.Manager()
does_not_exist = DoesNotExistBookManager()
class Meta:
ordering = ['-pubdate']
示例2: get_manager
# 需要导入模块: from django.db.models.manager import BaseManager [as 别名]
# 或者: from django.db.models.manager.BaseManager import from_queryset [as 别名]
def get_manager(cls):
return type('DictManager', (BaseManager.from_queryset(cls)), {})