【发布时间】:2021-05-16 07:34:09
【问题描述】:
模型包含一个jsonfield:
class MyModel(Model):
test_result = JSONField()
要处理的数据是动态的, {'test1':100,'test2':95,'test9':80,...} , { 'test2':60, 'test3':80,'test6 ':70,... } ...
我想找到'test2'的所有测试结果并将它们保存到一个列表中。
all_score_of_test2 =[x.test_result['test2'] for x in MyModel.objects.filter(test_result__has_keys=['test2'])]
它可以工作,但性能不好。有没有更快的方法来完成任务?我正在使用 postgresql13.1
【问题讨论】:
标签: django postgresql jsonfield