當前位置: 首頁>>代碼示例>>Python>>正文


Python manager.BaseManager類代碼示例

本文整理匯總了Python中django.db.models.manager.BaseManager的典型用法代碼示例。如果您正苦於以下問題:Python BaseManager類的具體用法?Python BaseManager怎麽用?Python BaseManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BaseManager類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_manager_methods

    def test_manager_methods(self):
        """
        This test ensures that the correct set of methods from `QuerySet`
        are copied onto `Manager`.

        It's particularly useful to prevent accidentally leaking new methods
        into `Manager`. New `QuerySet` methods that should also be copied onto
        `Manager` will need to be added to `ManagerTest.QUERYSET_PROXY_METHODS`.
        """
        self.assertEqual(
            sorted(BaseManager._get_queryset_methods(QuerySet).keys()), sorted(self.QUERYSET_PROXY_METHODS)
        )
開發者ID:shellfly,項目名稱:django,代碼行數:12,代碼來源:tests.py

示例2: __str__

    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']
開發者ID:CrazyChief,項目名稱:django,代碼行數:30,代碼來源:models.py

示例3: get_manager

 def get_manager(cls):
     return type('DictManager', (BaseManager.from_queryset(cls)), {})
開發者ID:primal100,項目名稱:django_easy_manager,代碼行數:2,代碼來源:queryset.py


注:本文中的django.db.models.manager.BaseManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。