Django filter JSONField list of dicts

前端 未结 3 1140
盖世英雄少女心
盖世英雄少女心 2020-12-03 21:31

I run Django 1.9 with the new JSONField and have the following Test model :

class Test(TimeStampedModel):
    actions = JSONField()

Let\'s

3条回答
  •  执笔经年
    2020-12-03 21:54

    You should be able to use a __contains lookup for this and pass queried values as list as documented here. The lookup would behave exactly like ArrayField. So, something like this should work:

    Test.objects.filter(actions__contains=[{'fixed_key_1': 'foo2'}])
    

提交回复
热议问题