我正在使用Django ORM从数据库中检索数据:
ws = Ws.objects.all()
ws = ws.filter(*q_objects, **filter_kwargs)
ws = ws.order_by(*sort_list)
ws = ws.annotate(created_unix=UnixTimestamp(F('created')), date_unix=UnixTimestamp(F('date')))))
total_sum = ws.aggregate(total=Sum('ts_time', output_field=DecimalField()))['total'])['total']
LIST_FIELDS[1], LIST_FIELDS[2] = 'created_unix', 'date_unix'
return JsonResponse({'table_data': list(ws.values_list(*LIST_FIELDS)), 'summ_time': total_sum}, safe=False) ```
我需要在LIST_FIELDs中添加一个新列,对于每对具有多个匹配字段的行,
例如: 对于LIST_FIELDS [0]和LIST_FIELDS [2]
LIST_FIELDS[0] | LIST_FIELDS[1] | LIST_FIELDS[2] | LIST_FIELDS[3] |
---|---|---|---|
1 | 1 | 3 | True |
1 | 1 | 2 | True |
2 | 1 | 1 | False |
1 | 1 | 2 | True |
1 | 1 | 3 | True |
我试着问GPT4,但T9固执地给我
ws = ws.annotate(
match=Case(
When(field1=F('field2'), then=Value(True)),
default=Value(False),
output_field=BooleanField()
)
)
但这就像一排比较field1 == field2
个
我需要真,如果row1[field1] == row2[field1] and row1[field2] == row2[field2]