将2个django查询结果连接成一个

时间:2013-09-18 06:36:08

标签: python django

res= table.objects.values('lat','lng')
res1 = table1.objects.values('lat','lng')

res1=[{'lat': u'22.216021036729217', 'lng': u'84.83377508819103'}]
res=[{'lat': u'15.898394035175443', 'lng': u'73.82306920364499'}]

我想将resres1的结果添加到poi中:

poi = [{'lat': u'15.898394035175443', 'lng': u'73.82306920364499'},{'lat': u'22.216021036729217', 'lng': u'84.83377508819103'} ] 

我尝试了poi=list(res)+list(res1),但收到了以下错误:

list referenced before assignment

1 个答案:

答案 0 :(得分:0)

您可以使用list运算符将ValuesQuerySet转换为列表

res= table.objects.values('lat','lng') res1 = table 1.objects.values('lat','lng')

poi = list(res) + list(res1)