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?
[GIS] GeoDjango: Order by distance for model that has a ForeignKey relation to another model that has a PointField
geodjango
Best Answer
Assuming that both Model
A
andB
are usingobjects = models.GeoManager()
, the FK field on Model A is namedb
, ModelB
hasPointField
namedpoint
, andpnt
is a GEOSGeometry then the following should work: