I'm using tastypie for the REST functionality which I have extended so that 
geolocation can be used as a filter, e.g.:

class TestResource(ModelResource):
    
    class Meta:
        queryset = Event.objects.all()
        resource_name='test'
        ordering = ['date_from']
        
    def get_object_list(self, request):
        _items = super(TestResource, self).get_object_list(request).all()
        if request.method == 'GET':
            if 'lat' in request.GET and 'lng' in request.GET and 'rad' in 
request.GET:
                _lat = float(request.GET['lat'].strip())
                _lng = float(request.GET['lng'].strip())
                self._current_location = Point(_lat, _lng)
                _items=_items.filter(
                        
Q(city__coordinates__distance_lte=(self._current_location, 
float(request.GET['rad'].strip())*1000))
                    )                    
        return _items                

    def dehydrate(self, bundle):
        bundle.data['lat'] = bundle.obj.city.coordinates.x
        bundle.data['lng'] = bundle.obj.city.coordinates.y
        bundle.data['distance'] = 
bundle.obj.city.coordinates.distance(self._current_location) 
* 100
        return bundle
      
Hope this helps, if you want I can include more code details...  
Rok

On Sunday, October 20, 2013 4:06:26 PM UTC+2, Sanjay Bhangar wrote:
>
> Hi all, 
>
> I'm developing an app using GeoDjango that requires me to create an 
> API. Ideally, I would output GeoJSON at various API end-points and 
> support a few geo-queries like "within bounding box", etc. 
>
> I have done something similar before without Django Rest Framework and 
> just writing vanilla views, but I thought it would be nice to make use 
> of a lot of the niceties that the framework provides. 
>
> Just wondering if something has dealt with serialization / 
> deserialization of geo models using Django Rest Framework and has any 
> pointers / code to share (or advice on why this is a bad idea :)). A 
> fair amount of internet searching did not turn up anything for me. 
>
> Looking through the docs, it seems like there are reasonable hooks to 
> write custom Serializer, Renderer and Filter classes - just wondering 
> if someone has gone down this road before - and also, potentially, if 
> someone else may find this useful and then I could think about making 
> whatever solution I come up with more generalizable .. 
>
> Also, if there's a better place to discuss this, please let me know :) 
>
> Thanks, 
> Sanjay 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fe94c4c1-2883-4214-92d2-84b68a787713%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to