title: GeoDjango GeoQuerySet.distance() results in 'ST_Distance output only available on GeometryFields' when specifying a reverse relationship in field_name
body: <p>From the docs and other questions, sorting a GeoQuerySet by distance should be straightforward, but I'm having trouble getting it work. Here is an example to demonstrate the situation of the problem:</p>
  
  <p>Lets say I got two models in two different apps. One model in appA and another in appB as defined below:</p>
  
  <pre><code># appA/models.py
  class Store(models.Model):
          title = models.CharField()
  
  
  # appB/models.py
  from appA.models import Store
  
  class StoreLocation(models.Model):
      store = models.ForiegnKey(Store)
      location = models.PointField()
  </code></pre>
  
  <p>Now, I want to get all the <code>Stores</code> that are within two miles of a user's location (<code>user_location</code>) like so:</p>
  
  <pre><code>stores = Store.objects.filter(storelocation__location__dwithin(user_location, D(mi=2))
  </code></pre>
  
  <p>So far so good. Everything up to here works. The problem starts when I want to now sort the <code>Stores</code> by their distance to <code>user_location</code>:</p>
  
  <pre><code>stores = Store.objects.filter(storelocation__location__dwithin(user_location, D(mi=2))\
           .distance(user_loc, field_name='storelocation__location')\
           .order_by('distance')
  </code></pre>
  
  <p>This results into <code>TypeError: ST_Distance output only available on GeometryFields</code>. </p>
  
  <p>The <code>location</code> field of the <code>StoreLocation</code> model is a <code>PointField</code> which is a <code>GeometryField</code>. So the issue is with the reverse relationship lookup done by <code>field_name='storelocation__location'</code>.</p>
  
  <p>There is a Django support ticket (<a href="https://code.djangoproject.com/ticket/22352" rel="nofollow noreferrer">https://code.djangoproject.com/ticket/22352</a>) requesting support for reverse relationship lookups in <code>field_name</code> for OneToOne relationships, but my models have a OneToMany relationship through a ForeignKey so I'm not sure if the support ticket applies to this problem.</p>
  
  <p>Judging from the Django documentation (<a href="https://docs.djangoproject.com/en/1.6/ref/contrib/gis/geoquerysets/#geoqueryset-methods" rel="nofollow noreferrer">https://docs.djangoproject.com/en/1.6/ref/contrib/gis/geoquerysets/#geoqueryset-methods</a>) it doesn't seem like I'm misusing anything here.</p>
  
  <p>Are reverse relationship lookups allowed with the <code>field_name</code> argument of GeoQuerySet methods? Or am I just doing something wrong?</p>
  
  <p>The solution provided in this question (<a href="https://stackoverflow.com/questions/5068457/geodjango-distance-query-for-a-foreignkey-relationship">GeoDjango distance query for a ForeignKey Relationship</a>) didn't help either.</p>