当前位置: 首页>>代码示例>>Python>>正文


Python jsonb.KeyTextTransform方法代码示例

本文整理汇总了Python中django.contrib.postgres.fields.jsonb.KeyTextTransform方法的典型用法代码示例。如果您正苦于以下问题:Python jsonb.KeyTextTransform方法的具体用法?Python jsonb.KeyTextTransform怎么用?Python jsonb.KeyTextTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.postgres.fields.jsonb的用法示例。


在下文中一共展示了jsonb.KeyTextTransform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filter

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def filter(self, qs, value):
        if value in EMPTY_VALUES:
            return qs

        for expr in value:
            if expr in EMPTY_VALUES:  # pragma: no cover
                continue

            lookup_expr = expr.get("lookup", self.lookup_expr)
            # "contains" behaves differently on JSONFields as it does on TextFields.
            # That's why we annotate the queryset with the value.
            # Some discussion about it can be found here:
            # https://code.djangoproject.com/ticket/26511
            if isinstance(expr["value"], str):
                qs = qs.annotate(
                    field_val=KeyTextTransform(expr["key"], self.field_name)
                )
                lookup = {f"field_val__{lookup_expr}": expr["value"]}
            else:
                lookup = {
                    f"{self.field_name}__{expr['key']}__{lookup_expr}": expr["value"]
                }
            qs = qs.filter(**lookup)
        return qs 
开发者ID:projectcaluma,项目名称:caluma,代码行数:26,代码来源:filters.py

示例2: create_activity_upcoming_notifications

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def create_activity_upcoming_notifications():
    # Oh oh, this is a bit complex. As notification.context is a JSONField, the participants_already_notified subquery
    # would return a jsonb object by default (which can't be compared to integer).
    # We can work around this by transforming the property value to text ("->>" lookup) and then casting to integer
    with timer() as t:
        participants_already_notified = Notification.objects.\
            order_by().\
            filter(type=NotificationType.ACTIVITY_UPCOMING.value).\
            exclude(context__activity_participant=None).\
            values_list(Cast(KeyTextTransform('activity_participant', 'context'), IntegerField()), flat=True)
        activities_due_soon = Activity.objects.order_by().due_soon()
        participants = ActivityParticipant.objects.\
            filter(activity__in=activities_due_soon).\
            exclude(id__in=participants_already_notified).\
            distinct()

        for participant in participants:
            Notification.objects.create(
                type=NotificationType.ACTIVITY_UPCOMING.value,
                user=participant.user,
                expires_at=participant.activity.date.start,
                context={
                    'group': participant.activity.place.group.id,
                    'place': participant.activity.place.id,
                    'activity': participant.activity.id,
                    'activity_participant': participant.id,
                },
            )

    stats_utils.periodic_task('notifications__create_activity_upcoming_notifications', seconds=t.elapsed_seconds) 
开发者ID:yunity,项目名称:karrot-backend,代码行数:32,代码来源:tasks.py

示例3: __call__

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def __call__(self, *args, **kwargs):
        return KeyTextTransform(self.key_name, *args, **kwargs) 
开发者ID:aropan,项目名称:clist,代码行数:4,代码来源:json_field.py

示例4: gen_facility_header

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def gen_facility_header(facility):
    return {
        'en': 'facilities_{}'.format(facility),
        'zh': '提供家具_{}?'.format(facility),
        'annotate': KeyTextTransform(facility,'facilities'),
    } 
开发者ID:g0v,项目名称:tw-rental-house-data,代码行数:8,代码来源:export_uniq_house.py

示例5: __init__

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def __init__(
        self,
        column,
        zh,
        en=None,
        field=None,
        enum=None,
        annotate=None,
        fn=None,
        child_fields=[]):

        self.column = column
        self.zh = zh
        self.en = en if en else column
        self.field = field
        self.annotate = annotate
        self.fn = fn
        self.child_fields = []

        if field:
            self.en = '{}_{}'.format(self.en, field)

        if not annotate and self.field:
            self.annotate = KeyTextTransform(self.field, self.column)

        for child in child_fields:
            self.child_fields.append(Field(**child)) 
开发者ID:g0v,项目名称:tw-rental-house-data,代码行数:29,代码来源:field.py

示例6: value

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def value(self):
        return self.annotate(
            value=Cast(KeyTextTransform('value', 'form_data'), output_field=FloatField())
        ).aggregate(
            Count('value'),
            Avg('value'),
            Sum('value'),
        ) 
开发者ID:OpenTechFund,项目名称:hypha,代码行数:10,代码来源:submissions.py

示例7: activity_modified

# 需要导入模块: from django.contrib.postgres.fields import jsonb [as 别名]
# 或者: from django.contrib.postgres.fields.jsonb import KeyTextTransform [as 别名]
def activity_modified(sender, instance, **kwargs):
    activity = instance

    # abort if activity was just created
    if not activity.id:
        return

    old = Activity.objects.get(id=activity.id)

    participants = activity.activityparticipant_set

    def delete_notifications_for_participants(participants, type):
        Notification.objects.order_by().not_expired() \
            .filter(type=type) \
            .annotate(participant_id=Cast(KeyTextTransform('activity_participant', 'context'), IntegerField())) \
            .filter(participant_id__in=participants.values_list('id', flat=True)) \
            .delete()

    if old.is_disabled != activity.is_disabled:
        if activity.is_disabled:
            delete_notifications_for_participants(
                participants=participants,
                type=NotificationType.ACTIVITY_UPCOMING.value,
            )

            Notification.objects.create_for_activity_participants(
                participants=participants.exclude(user=activity.last_changed_by),
                type=NotificationType.ACTIVITY_DISABLED.value,
            )
        else:
            # activity is enabled
            Notification.objects.create_for_activity_participants(
                participants=participants.exclude(user=activity.last_changed_by),
                type=NotificationType.ACTIVITY_ENABLED.value,
            )
            # activity_upcoming notifications will automatically get created by cronjob

    if abs((old.date.start - activity.date.start).total_seconds()) > 60:
        Notification.objects.create_for_activity_participants(
            participants=participants.exclude(user=activity.last_changed_by),
            type=NotificationType.ACTIVITY_MOVED.value,
        )


# Issue 
开发者ID:yunity,项目名称:karrot-backend,代码行数:47,代码来源:receivers.py


注:本文中的django.contrib.postgres.fields.jsonb.KeyTextTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。