Mon 19 August 2013
from cities.models import City
cape_town = City.objects.filter(country__name='South Africa').get(name='Cape Town')
nearest = City.objects.distance(cape_town.location).exclude('distance')[:10000]

I must be very damaged from location data being badly implemented in MySQL. I'm still amazed that this request could be under a second, let alone be pretty much instant. Postgis is basically the coolest thing ever.

Oh and in case you were curious(which you weren't), this place is in terms of distance the 10000th closest place to Cape Town.

Category: Django Tagged: geolocation python django postgres