0

我不想经历安装 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.

4

1 回答 1

0

libgeos-dev在某些情况下,安装包应该可以解决这个错误。

于 2014-03-20T17:00:29.340 回答