how to write a query to get find value in a json field in django

If you are using the django-jsonfield package, then this is simple. Say you have a model like this:

from jsonfield import JSONField
class User(models.Model):
    jsonfield = JSONField()

Then to search for records with a specific username, you can just do this:

User.objects.get(jsonfield__contains={'username':username})

Leave a Comment