且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django,哪个功能属于QuerySet和Manager?

更新时间:2023-11-28 21:59:16

能够访问管理器上的count()查询集上的某些功能是很有意义的.这使您可以执行以下操作:

It makes sense to be able to access some functions like count() on the manager and the queryset. This allows you to do:

Blog.objects.count()  # total number of blogs
Blog.objects.filter(status='PUBLISHED').count()  # Number of published blogs

Django具有方法 as_manager ,可让您从自定义查询集中创建管理器.这意味着您不必在管理器和查询集上重复您的方法.

Django has a method as_manager which allows you to create a manager from a custom queryset. This means you don't have to duplicate your methods on the manager and queryset.