-1
class Modex(baseModal):

    sdgdList = BinaryJSONField(verbose_name="sdgdList",null=True,)

sdgdList 数据:

[{“x”:“1”,“cgs”:“11.00”,“gbxz”:“A”,“gdmc”:“aaa”,“zjqk”:“0.48”,“zzgs”:“0.18”, “zjqkCss”:“red”,“gdblockid”:“10”,},{“x”:“2”,“cgs”:“10.06”,“gbxz”:“A”,“gdmc”:“bbb” ,“zjqk”:“0.32”,“zzgs”:“0.17”,“zjqkCss”:“红色”,“gdblockid”:“10”,},{“x”:“2”,“cgs”:“10.06” ","gbxz":"A","gdmc":"aaa","zjqk":"0.32","zzgs":"0.17","zjqkCss":"red","gdblockid":"10", }]

如何过滤 'gdmc' == 'aaa' 然后结果:

[{“x”:“1”,“cgs”:“11.00”,“gbxz”:“A”,“gdmc”:“aaa”,“zjqk”:“0.48”,“zzgs”:“0.18”, “zjqkCss”:“red”,“gdblockid”:“10”,},{“x”:“2”,“cgs”:“10.06”,“gbxz”:“A”,“gdmc”:“aaa” ,“zjqk”:“0.32”,“zzgs”:“0.17”,“zjqkCss”:“红色”,“gdblockid”:“10”,}]

#没用!Modex.select().where(Modex.sdgdList['gdmc'] == 'aaa') 过滤 dict 它的工作,

{'gdmc':[1,2,'abc','bbb']}
4

1 回答 1

0

由于您的 json 数据是字典列表,因此您可以这样做:

MyModel.select().where(MyModel.sdgdList.contains([{'gdmc': 'aaa'}]))
于 2020-11-19T17:58:07.030 回答