将 geodjango 查询 return 距离作为属性?

Getting geodjango query to return distance as an attribute?

有没有办法查询 return 每个位置到该点的距离? 现在我有 Location.objects.filter(geometry__distance_lte=(pnt, D(mi=20))) 但行没有距离属性。如何获得 returned 的每一行与 pnt 的距离?

我遇到了同样的问题,原因是 "In order to conduct geographic queries, each geographic model requires a GeoManager model manager."

https://docs.djangoproject.com/en/1.8/ref/contrib/gis/model-api/#django.contrib.gis.db.models.GeoManager

解决方案是将 objects = models.GeoManager() 添加到您的位置模型

from django.contrib.gis.db import models

class Location(models.Model):
    ...
    objects = models.GeoManager()