Created
July 6, 2011 13:07
-
-
Save bohde/1067176 to your computer and use it in GitHub Desktop.
Tastypie support for Geodjango distance filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Hi, great example! Do you have any idea how to include the distance in tastypie's fields? Just including it like fields = [... 'distance'] doesnt work.