title: Django order_by on a nested json field
body: <p>My models are something like this.</p>
  
  <pre><code>class Foo():
      bar = models.ForeignKey('Bar', related_name='bar')
      payload = JSONField()
  
  class Bar():
      candy = models.ForeignKey('Candy', related_name='candy')
  
  class Candy():
      payload = JSONField()
  </code></pre>
  
  <p>My queryset looks something like this</p>
  
  <pre><code># I want to order by a name on the json field
  queryset = [
  {
    "id": 1,
    "payload": {"age": 10, "company": "ccc"}
    "bar": 
     {
       'id': 1,
        "candy":
         {
          "payload": 
             {
             "names": ["text":"abc", "tag":"foo"], ["text":"abb", "tag":"bar"]
             }
         }
     }
   }, 
   {
    "id": 2,
    "payload": {"age": 12, "company": "aa"}
    "bar": 
     {
       'id': 2,
        "candy":
         {
          "payload": 
             {
             "names": ["text":"aaa", "tag":"bar"], ["text":"bbb", "tag":"bart"]
             }
         }
     }
   }]
  
  
  foo = Foo.objects.all() #now I want to order foo by "names.text"
  </code></pre>
  
  <p>This is what I have tried so far</p>
  
  <pre><code>foo = foo.order_by(RawSQL("payload-&gt;&gt;%s", ("age",))) #this works!!
  foo = foo.order_by(RawSQL("bar.candy.payload-&gt;&gt;%s", ("names[0].text",))) #does not work
  </code></pre>
  
  <p>The second statement does not work. I got inspiration to use <code>RawSQL</code> from here 
  <a href="https://stackoverflow.com/questions/36641759/django-1-9-jsonfield-order-by">Django 1.9 JSONField order_by</a></p>
  
  <p>I cannot figure out how to navigate to that particular class and then execute the query. What is the best way to do this?</p>