title: Using django query set values() to index into JSONField
body: <p>I am using django with postgres, and have a bunch of JSON fields (some of them quite large and detailed) within my model.  I'm in the process of switching from char based ones to jsonb fields, which allows me to <code>filter</code> on a key within the field, and I'm wondering if there is any way to get the equivalent benefit out of a call to the query set <code>values</code> method.</p>
  <h3>Example:</h3>
  <p>What I would like to do, given a <code>Car</code> model with <code>options</code> JSONField, is something like</p>
  <pre><code>qset = Car.objects.filter(options__interior__color='red')
  vals = qset.values('options__interior__material')
  </code></pre>
  <p>Please excuse the lame toy problem, but hopefully it gets the idea across.  Here the <code>filter</code> call does exactly what I want, but the call to <code>values</code> does not seem to be aware of the special nature of the JSON field.  I get an error because <code>values</code> can't find the field called &quot;interior&quot; to join on.  Is there some other syntax or option that I am missing that will make this work?</p>
  <p>Seems like a pretty obvious extension to the existing functionality, but I have so far failed to find any reference to something similar in the docs or through stack overflow or google searches.</p>
  <h3>Edit - a workaround:</h3>
  <p>After playing around, looks like this could be fudged by inserting the following in between the two lines of code above:</p>
  <pre><code>qset=qset.annotate(options__interior__material=RawSQL(&quot;SELECT options-&gt;'interior'-&gt;'material'&quot;,()))
  </code></pre>
  <p>I say &quot;fudged&quot; because it seems like an abuse of notation and would require special treatment for integer indices.</p>
  <p>Still hoping for a better answer.</p>