1

I have a json field for a model in my Django app that typically has nested json in it. I read that to filter on a JSONfield, you would use contains on the filter for whatever value you are looking for, but I'm not getting any results back even though I know the value does exist in the JSONField. Is there an extra step I need to use for nested json in a json field?

JSON Field "Field name is Content "

"content": {
    "documents": [
        {
             "id": "378",
             "name": "Test.pdf",
             "mediaFile": "http://localhost:8000/media/file.pdf"
        }
    ]
}

Query:

document_modules = 
 WMDocumentModule.objects.filter(content__documents__contains={'id': "378"})

>>> document_modules: <QuerySet []>
Marcus Lind
  • 10,374
  • 7
  • 58
  • 112
TJB
  • 3,706
  • 9
  • 51
  • 102
  • 3
    Can you try `WMDocumentModule.objects.filter(content__documents__contains=[{'id': "378"}])`? It looks like the closest to `__values__contains` modify on `ArrayField`. – Oluwafemi Sule Jan 30 '18 at 22:12
  • Sorry for the late replay. That did work ! thank you : ) – TJB Jan 31 '18 at 19:11

0 Answers0