PostGIS をインストールする手間をかけたくないので、 を使用して原点からの距離で並べ替えられた場所を取得できdjango.contrib.gis
ますか?
models.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.