Hi Rok,
Thank you so much for the reply and code snippets. I think I managed
to implement the stuff I needed using the hooks provided by
Django-Rest-Framework -- not 100% sure why I picked that over Tastypie
for this, but its treating me well, so I'll stick to it ..
Since we're sharing code :), this is what I came up with to handle
filtering by bbox and distance to a point -- this is obviously first
draft code, but it seemed to work quite well --
class VirtualCacheList(generics.ListAPIView):
serializer_class = VirtualCacheListSerializer
def get_queryset(self):
qset = VirtualCache.objects.all()
params = self.request.QUERY_PARAMS
username = params.get('username', None)
if username is not None:
qset = qset.filter(user__username=username)
bbox_string = params.get('bbox', None)
if bbox_string:
bbox = [float(b) for b in bbox_string.split(",")]
qset = qset.filter(point__within=bbox)
distance = params.get("distance", None)
lat = params.get("lat", None)
lon = params.get("lon", None)
if distance and lat and lon:
lat = float(lat)
lon = float(lon)
distance = int(distance)
point = Point(lat, lon)
qset = qset.filter(point__distance_lte=(point,
D(m=distance),)).distance(point, field_name='point')
qset = qset.order_by('distance')
return qset
I probably want to implement that as a Filter class or so - I will
look at the django-restframework-gis packages for an idea of the
cleanest way to do it, but it's super nice how easy these frame-works
have made it to get a fully functional api with docs and everything.
I'll probably bug the people over at the Django Rest Framework mailing
list if I run into issues, but so far I found ways to do everything I
needed to do - just the GeoJSON serialization seemed awkward, but I
see there's a package for that, so I seem to be sorted.
Thanks again,
Sanjay
>
https://groups.google.com/d/msgid/django-users/fe94c4c1-2883-4214-92d2-84b68a787713%40googlegroups.com.