0

I don't want to go through the pain of installing PostGIS so can I get places ordered by distance from an origin using 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)

views.py

origin = Point(lookup_lat,lookup_lng)
places = Place.objects.filter(point__distance_lte=(origin, D(mi=10))).distance(origin).order_by('distance')[:20]

I've tried this but I get Cannot resolve keyword 'point' into field.

Robert Johnstone
  • 5,431
  • 12
  • 58
  • 88

1 Answers1

0

Installing the package libgeos-dev should solve this error in some of the cases.

Forge
  • 6,538
  • 6
  • 44
  • 64