4

Model A has a ForeignKey relation to Model B. Model B has a PointField. Is there a way to order Model A objects by distance from a POINT?

4

Assuming that both Model A and B are using objects = models.GeoManager(), the FK field on Model A is named b, Model B has PointField named point, and pnt is a GEOSGeometry then the following should work:

A.objects.distance(pnt, field_name='b__point').order_by('distance')
  • thanks. i have yet to try this, but it looks promising. is this documented somewhere? i couldn't find it... – kliao Dec 31 '10 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.