I use the json field in my django model:
class JsonTable(models.Model): data = JSONField() type = models.IntegerField()
I tried the following query, which works for normal sql fields:
JsonTable.objects.filter(type=1).values('type').annotate(Avg('data__superkey'))
But this causes the following error:
FieldError: Cannot resolve keyword 'superkey' into field. Join on 'data' not permitted.
Is there a way to make a group by json key using Django ORM or some python library without using raw sql?
Versions: Django 1.9b, PostgreSQL 9.4
UPDATE
Example 2:
JsonTable.objects.filter(type=1).values('data__happykey').annotate(Avg('data_superkey'))
causes the same error on happykey
json python django postgresql
Zhassulan Nurushev
source share