我不想经历安装 PostGIS 的痛苦,所以我可以使用与原点的距离来排序位置django.contrib.gis
吗?
模型.py
from django.contrib.gis.geos import Point
class Place(models.Model):
name = models.CharField(max_length=50)
lat = models.FloatField()
lng = models.FloatField()
def point(self):
return Point(self.lat,self.lng)
视图.py
origin = Point(lookup_lat,lookup_lng)
places = Place.objects.filter(point__distance_lte=(origin, D(mi=10))).distance(origin).order_by('distance')[:20]
我已经尝试过了,但我得到了Cannot resolve keyword 'point' into field.