我在view.py中有这样的查询集:
SomeValue = list(a.objects.filter(x=x_number, timestamp__gte=a_time, timestamp__lte=b_time) \
.order_by('timestamp').values_list('timestamp', 'some_index').annotate(
some1=dosomething('some_index'),
some2=dosomething('some_index_2'),
combined_some=(F('some1') + F('some2'))
))
所以SomeValue看起来像这样:
SomeValue = [(datetime.datetime(2017, 7, 20, 23, 53, 51, tzinfo=<UTC>), 2L, 10.1, 2.4, 12.5), (datetime.datetime(2017, 7, 20, 23, 54, 51, tzinfo=<UTC>), 8L, 5.5, 6.4, 11.9), (datetime.datetime(2017, 7, 20, 23, 55, 51, tzinfo=<UTC>), 4L, 7.2, 2.0, 9.2),...]
我的目标是访问SomeValue并获得像这样的combined_some:
combined_some = [(datetime.datetime(2017, 7, 20, 23, 53, 51, tzinfo=<UTC>), 12.5), (datetime.datetime(2017, 7, 20, 23, 54, 51, tzinfo=<UTC>), 11.9), (datetime.datetime(2017, 7, 20, 23, 55, 51, tzinfo=<UTC>), 9.2),...]
答案 0 :(得分:1)
这是你在找什么?
combined_some = [(i[0], i[-1]) for i in SomeValue]