Skip to content

Instantly share code, notes, and snippets.

@nisc
Forked from bohde/resources.py
Created January 2, 2012 16:33
Show Gist options
  • Save nisc/1551309 to your computer and use it in GitHub Desktop.
Save nisc/1551309 to your computer and use it in GitHub Desktop.
Tastypie support for Geodjango distance filtering
class MyGeoResource(Resource):
def apply_sorting(self, objects, options=None):
if options and "longitude" in options and "latitude" in options:
return objects.distance(Point(options['latitude'], options['longitude'])).order_by('distance')
return super(MyGeoResource, self).apply_sorting(objects, options)
curl localhost:8000/api/v1/mygeoresource?latitude=<>&longitude=<>&limit=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment