當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Django BoolAnd用法及代碼示例

本文介紹 django.contrib.postgres.aggregates.BoolAnd 的用法。

聲明

class BoolAnd(expression, filter=None, default=None, **extra)

如果所有輸入值都為真,則返回 True ,如果所有值都為空或沒有值,則返回 default ,否則返回 False

使用示例:

class Comment(models.Model):
    body = models.TextField()
    published = models.BooleanField()
    rank = models.IntegerField()

>>> from django.db.models import Q
>>> from django.contrib.postgres.aggregates import BoolAnd
>>> Comment.objects.aggregate(booland=BoolAnd('published'))
{'booland': False}
>>> Comment.objects.aggregate(booland=BoolAnd(Q(rank__lt=100)))
{'booland': True}

相關用法


注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.contrib.postgres.aggregates.BoolAnd。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。