Skip to content

Instantly share code, notes, and snippets.

@ns-1m
Forked from bohde/resources.py
Created April 15, 2012 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ns-1m/2389330 to your computer and use it in GitHub Desktop.
Save ns-1m/2389330 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
@ns-1m
Copy link
Author

ns-1m commented Apr 15, 2012

Related to Ajax call

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"latlong": "test"}' http://localhost:8000/geo/api/geolocation/

$.ajax({
type: 'POST',
url: 'http://localhost:8000/geo/api/geolocation/',
data: '{"latlong": "test"}',
success: latlongSaved(),
dataType: "application/json",
processData: false,
contentType: "application/json"
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment