Django annotate specific keys in json fields : <p>I'm using Django 1.9 and Postgres 9.5. I have a model (<code>MyModel</code>) with a <code>JSONField</code> (<code>django.contrib.postgres.fields</code>). The JSON value has the same structure in all the objects in the model.</p>

<pre><code>{
"key1": int_val_1,
"key2": int_val_2
}
</code></pre>

<p>I want to order my queryset by a value of a specified key in my <code>JSONField</code>. Something like</p>

<pre><code>MyModel.objects.annotate(val=F('jsonfield__key1')).order_by('val')
</code></pre>

<p>This does not work - i get the following error </p>

<pre><code>Cannot resolve keyword 'key1' into field. Join on 'jsonfield' not permitted.
</code></pre>

<p>Is there anyway i can achieve this?</p>
