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 can't understand why sorting is not working.
Best Answer
Did anyone figure this one out already to the end? Two options I have tried so far: Proxy model
add_to_class
But I keep hitting "ST_Distance output only available on GeometryFields. ()" ... Everything is a point and using field_name
Don't know if this could help.
Update 06/10/2012
So I have been further investigating into this and I'm still not quite getting there. When building a queryset and defining the field_name, I receive mentioned error about GeometryFields. I even went so far to update the auth.User in contrib to include the GeoManager, but this did not change anything. When however building the queryset straight on UserProfile and thus not having to define field_name, things Just Work. Don't know if this is a bug? Since I have found some posts on the net that confirm field_name is working...