I'm using django 1.9 with its built-in JSONField and postgres 9.4. In my model's attrs json field I store objects with some values, including numbers. And I need to aggregate over them to find min/max values. Something like this:
Model.objects.filter(**some).aggregate(min=Min('attrs__my_key'))
Also it would be useful to extract specific keys:
Model.objects.filter(**some).values_list('attrs__my_key', flat=True)
The above queries fail with FieldError: "Cannot resolve keyword 'my_key' into field. Join on 'attrs' not permitted."
Is it possible somehow?
I've started to dig into query expressions but without any success yet.