当前位置: 首页>>代码示例>>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;未经允许,请勿转载。