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


Python query.Q屬性代碼示例

本文整理匯總了Python中django.db.models.query.Q屬性的典型用法代碼示例。如果您正苦於以下問題:Python query.Q屬性的具體用法?Python query.Q怎麽用?Python query.Q使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.db.models.query的用法示例。


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

示例1: _get_next_or_previous_by_FIELD

# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import Q [as 別名]
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
        if not self.pk:
            raise ValueError("get_next/get_previous cannot be used on unsaved objects.")
        op = 'gt' if is_next else 'lt'
        order = '' if is_next else '-'
        param = force_text(getattr(self, field.attname))
        q = Q(**{'%s__%s' % (field.name, op): param})
        q = q | Q(**{field.name: param, 'pk__%s' % op: self.pk})
        qs = self.__class__._default_manager.using(self._state.db).filter(**kwargs).filter(q).order_by(
            '%s%s' % (order, field.name), '%spk' % order
        )
        try:
            return qs[0]
        except IndexError:
            raise self.DoesNotExist("%s matching query does not exist." % self.__class__._meta.object_name) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:base.py

示例2: _get_next_or_previous_by_FIELD

# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import Q [as 別名]
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
        if not self.pk:
            raise ValueError("get_next/get_previous cannot be used on unsaved objects.")
        op = 'gt' if is_next else 'lt'
        order = '' if is_next else '-'
        param = getattr(self, field.attname)
        q = Q(**{'%s__%s' % (field.name, op): param})
        q = q | Q(**{field.name: param, 'pk__%s' % op: self.pk})
        qs = self.__class__._default_manager.using(self._state.db).filter(**kwargs).filter(q).order_by(
            '%s%s' % (order, field.name), '%spk' % order
        )
        try:
            return qs[0]
        except IndexError:
            raise self.DoesNotExist("%s matching query does not exist." % self.__class__._meta.object_name) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:17,代碼來源:base.py

示例3: update_messages_for_topic_edit

# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import Q [as 別名]
def update_messages_for_topic_edit(message: Message,
                                   propagate_mode: str,
                                   orig_topic_name: str,
                                   topic_name: Optional[str],
                                   new_stream: Optional[Stream]) -> List[Message]:
    propagate_query = Q(recipient = message.recipient, subject__iexact = orig_topic_name)
    if propagate_mode == 'change_all':
        propagate_query = propagate_query & ~Q(id = message.id)
    if propagate_mode == 'change_later':
        propagate_query = propagate_query & Q(id__gt = message.id)

    messages = Message.objects.filter(propagate_query).select_related()

    update_fields: Dict[str, object] = {}

    # Evaluate the query before running the update
    messages_list = list(messages)

    # The cached ORM objects are not changed by the upcoming
    # messages.update(), and the remote cache update (done by the
    # caller) requires the new value, so we manually update the
    # objects in addition to sending a bulk query to the database.
    if new_stream is not None:
        update_fields["recipient"] = new_stream.recipient
        for m in messages_list:
            m.recipient = new_stream.recipient
    if topic_name is not None:
        update_fields["subject"] = topic_name
        for m in messages_list:
            m.set_topic_name(topic_name)

    messages.update(**update_fields)

    return messages_list 
開發者ID:zulip,項目名稱:zulip,代碼行數:36,代碼來源:topic.py

示例4: _get_next_or_previous_by_FIELD

# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import Q [as 別名]
def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
        if not self.pk:
            raise ValueError("get_next/get_previous cannot be used on unsaved objects.")
        op = is_next and 'gt' or 'lt'
        order = not is_next and '-' or ''
        param = force_text(getattr(self, field.attname))
        q = Q(**{'%s__%s' % (field.name, op): param})
        q = q | Q(**{field.name: param, 'pk__%s' % op: self.pk})
        qs = self.__class__._default_manager.using(self._state.db).filter(**kwargs).filter(q).order_by('%s%s' % (order, field.name), '%spk' % order)
        try:
            return qs[0]
        except IndexError:
            raise self.DoesNotExist("%s matching query does not exist." % self.__class__._meta.object_name) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:15,代碼來源:base.py

示例5: pending_for

# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import Q [as 別名]
def pending_for(self, instance):
        ct = ContentType.objects.get_for_model(instance)
        now = timezone.now()
        return self.exclude(confirmed=True).filter(content_type=ct,
                object_pk=instance.pk).filter(
                Q(valid_until__gt=now) | Q(valid_until__isnull=True)).count() 
開發者ID:arneb,項目名稱:django-generic-confirmation,代碼行數:8,代碼來源:models.py


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