title: How to aggregate (min/max etc.) over Django JSONField data?
body: <p>I'm using Django 1.9 with its built-in <code>JSONField</code> and Postgres 9.4.
  In my model's <code>attrs</code> 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:</p>
  
  <pre><code>Model.objects.aggregate(min=Min('attrs__my_key'))
  </code></pre>
  
  <p>Also, it would be useful to extract specific keys:</p>
  
  <pre><code>Model.objects.values_list('attrs__my_key', flat=True)
  </code></pre>
  
  <p>The above queries fail with </p>
  
  <blockquote>
    <p>FieldError: "Cannot resolve keyword 'my_key' into field. Join on 'attrs' not permitted."</p>
  </blockquote>
  
  <p>Is it possible somehow?</p>
  
  <p>Notes:</p>
  
  <ol>
  <li>I know how to make a plain Postgres query to do the job, but am searching specifically for an ORM solution to have the ability to filter etc.</li>
  <li>I suppose this can be done with a (relatively) new query expressions/lookups API, but I haven't studied it yet.</li>
  </ol>