14 ms·
Sure you can. See the documentation: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#querying-jsonfield https://docs.djangoproject.com/en/2.0
by akx 8y ago
Sure you can. See the documentation: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#querying-jsonfield https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/f...
- oneweekwonder 8y agoThank for the quick reply. Now I need to understand how the "__" magic work; And I wonder what would django do if my key is "animal__breed". Will it understand: Dog.objects.filter(data__animal__breed='collie') But this is maybe questions I should rather ask on #django or stackoverflow.
- strig 8y agoDjango won't let you name a model field with a double underscore, I believe. Not sure how this would work with a Postgres JSON type column though, but it would probably throw an error.
- akx 8y agoYou probably simply can't do a `data['animal__breed']` query (not with that syntax anyway; you can implement custom lookups though) if your key happens to contain a double underscore.