0

I have a model with a JSONField. The JSON field contains a title that I'd like to use to identify the object. Obviously, I can just use a loop, checking if each object contains the title I'm looking for. But I was wondering if there was a more pythonic way to do it. Something like this:

myObj = MyModel.objects.get(myjson__title='Title')

The above code doesn't work, obviously. But is there an approach that can be taken without using a loop?

  • @MoinuddinQuadri I did give you an upvote because I think you were on the right track, but it didn't work when I tried it so I can't accept it because it didn't solve my problem. – Shaymin Gratitude Aug 25 '16 at 19:11

1 Answers1

1

I am assuming title is the key in the JSONField

myObj = MyModel.objects.get(myjson__contains={'title':'Title'})
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126