當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。