[Fixed]-Django MySQL Query Json field

1👍

It depends on how exactly do you store JSON in field. If you use django-jsonfield, then your things will be string without spaces, with strings inside of quotation marks: '{"value1":"phil","value2":"jill"}'.

Then, via docs:

my_things = my_things.filter(things__contains='"value1":"phil"')

should return your filtered QuerySet, because

>>> tmp_str = '{"value1":"phil","value2":"jill"}'
>>> '"value1":"phil"' in tmp_str
True

Leave a comment