Search code examples
pythondjangodistancepostgisdjango-1.8

Django 1.8, Postgis Querying distance between two points


In a tutorial i saw the distance calculation between a given point and points in db.

from django.contrib.gis.db.models.functions import Distance

But Django 1.8 didn't have above "functions" module. So how can i achieve the same result as the query below in 1.8

qs = qs.annotate(distance=Distance('location', pnt)).order_by('distance')

I looked at Geo database api docs. But i got confused.


Solution

  • In Django 1.8 you should use GeoQuerySet.distance() method, take a look here https://docs.djangoproject.com/en/1.8/ref/contrib/gis/db-api/#distance-queries