I need to filter some objects that have no specific value in the field. I tried to do it like this:
MyModel.objects\
.filter(<some filters>)\
.exclude(json_field__has_key='some_field', json_field__some_field=True)
But this code generates wrong SQL query:
...
AND NOT (
"my_model"."json_field" ? some_field AND
("my_model"."json_field" -> 'some_field') = 'true' AND
"my_model"."json_field" IS NOT NULL)
)
...
On the first line some_field
used without qoutes. I fixed it by adding single qoutes to the string like this: json_field__has_key="'some_field'"
but I dont think it's a good solution.
Does anyone have an idea why it works this way and how I should fix it?