Skip to content
This repository
Browse code

add 'limit' parameter to location search

  • Loading branch information...
commit 8dc28e7bc47f7f7d86cb84d6f69189d4d0e34c35 1 parent 401b92e
Matt Westcott gasman authored

Showing 2 changed files with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 0  api/endpoints.txt
  2. +6 1 backend/api/handlers.py
1  api/endpoints.txt
@@ -14,6 +14,7 @@ Available API endpoints
14 14 lat / lng - if passed, locations are returned in ascending order of distance,
15 15 and include a 'distance_metres' field
16 16 max_distance - maximum distance in metres; lat/lng must also be passed
  17 + limit - maximum number of results to return
17 18
18 19 /api/{locale}/location/{id}/
19 20 details of the location with the specified ID
7 backend/api/handlers.py
@@ -63,7 +63,12 @@ def read(self, request, locale_slug):
63 63 if request.GET.get('max_distance'):
64 64 base = base.filter(point__distance_lte=(my_location, D(m=request.GET['max_distance'])))
65 65
66   - return base.distinct()
  66 + results = base.distinct()
  67 +
  68 + if request.GET.get('limit'):
  69 + results = results[:request.GET['limit']]
  70 +
  71 + return results
67 72
68 73 class LocationHandler(BaseHandler):
69 74 allowed_methods = ('GET',)

0 comments on commit 8dc28e7

Please sign in to comment.
Something went wrong with that request. Please try again.