我有两个查询集('a'和'b')使用
ldid=3
a=Ld.objects.filter(id=ldid).values()
b=Ld.objects.get(id=ldid).ldref.all().values()
结果:a和b的类型是<class 'django.db.models.query.QuerySet'>a
是
<QuerySet ['id ':3,'docref':'228689',' deno':'ESGF387054',' dedt':'20200905',' bjno':'ESGF387054',' bjdt':'20200905',' ccode_id':3,'gcode_id':6,'smcd_id':3,'cmcd_id':1,'schmcd_id':6,'invno':'2015407629',' invdt':'20200905',' item ':'MOBILE',' brnd':'VIVO',' pref1':'X50 KC472228',' pref2':'','invamt':'34990',' intper':“0”,“intamt”:“0”,“emitot”:'18',' emiamt':'1944',' emiano':'6',' emiaamt':'11664','名称':'23327',' Inbal':'23328',' ddt ':'20201010',' cldt':'','szdt':'','szrem':'','lstatus':'','ndeno':'462DDFGF387054',' ntdue':'23328',' ntrcpt':'21384',' nbal':1944年b
是
<QuerySet ['id ':3,'rtref':'2196146',' ldref_id':3,'rtno':' E504744','rtdt':'20210605',' emi':'1944','笔':“0”,“remlt”:'false'},'id':4,'rtref':'2196147',' ldref_id':3,'rtno':' E504745','rtdt':'20210605',' emi':'1333','笔':“0”,“remlt”:'false'},'id':5,'rtref':'2196148',' ldref_id':3,'rtno':' E504746','rtdt':'20210605',' emi':'1545','笔':“0”,“remlt”:'false'}]>
需要将它们转换为单个字典,引入新的键1,2,3,4等。并从查询集中计算字典的值。
比如
`context ={1:'id ':3,' docref ':'228689',etc.,},--> from a 2:{'id ':3,' rtref ':'2196146',' ldref_id':3,'rtno':'E504744',etc.,},
以用作细节视图模板渲染中的上下文。
我应该说,我在谷歌上搜索了很多东西。我需要一个简单优雅的方式来解压缩这2个查询集,使1字典。
1条答案
按热度按时间t9eec4r01#
试试这个:
这将返回所有记录