I need to order my query model by distance, however the point field in question is not on the model class but on the user profile and the i am getting an error when attempting the following.
g = geocoders.Google(domain='maps.google.co.uk')
place, (lat, lng) = g.geocode('SW1')
MyModel.objects.distance(Point(lat, lng), field_name='user__userprofile__location').order_by('distance')
The error i get is "ST_Distance output only available on GeometryFields"
Both MyModel and UserProfile have a GeoManager but obviously User does not.
Filtering works fine using
MyModel.objects.filter(user__userprofile__location__distance_lte=(Point(lat, lng), D(mi=distance)))
But i cant understand why sorting is not working. Any help or workaround would be really appreciated.