I am using django postgres JSONfield and the model structure is as below
from django.contrib.postgres.fields import JSONField
class JsonAnswer(models.Model):
name = models.CharField(max_length=255)
data = JSONField(default={})
the data present in the Json field is as below
{
"owner":{
"name":"Bob",
"other_pets":[
{
"name":"fishy"
}
]
},
"bread":"lab"
}
and my filter query is like this
JsonAnswer.objects.filter(data__owner__name="Bob")
which is throwing the error
FieldError: Unsupported lookup 'owner' for JSONField or join on the field not permitted.
Please explain how to filter the json field data
dict
ordict()
instead of{}
, because it "creates a mutable default that is shared between all instances of JSONField".. see docs – Pelaga