带有 BinaryJSONField 的 peewee 过滤器?

peewee filter with BinaryJSONField?

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”:“红色”,“gdblockid”:“10”,},{“x”:“2”,“cgs”:“10.06”,“gbxz”:“A”,“gdmc” ": "bbb", "zjqk": "0.32", "zzgs": "0.17", "zjqkCss": "red", "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": "red", "gdblockid": "10", }]

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

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

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

MyModel.select().where(MyModel.sdgdList.contains([{'gdmc': 'aaa'}]))