I’m trying to assemble a query from values supplied through GET requests, is this at all possible? Here’s an example of what I’m hoping to do:
def kml(request):
venues = Venue.objects.filter(
(Q(neighborhood__city__metro__slug=request.GET.get('metro')) if request.GET.get('metro')),
(Q(neighborhood__slug=request.GET.get('neighborhood')) if request.GET.get('metro'))
)
return HttpResponse(venues)
Basically, if I go to foo.com/?metro=nyc it’d return all Venue objects for that Metropolitan Area. If I only supply the neighborhood foo.com/?neighborhood=soho, it’d return all venues for any neighborhood named Soho. Finally, foo.com/?metro=nyc&neighborhood=soho would supply any venue meeting both the Metropolitan Area and Neighborhood criteria.
Is this possible?
ps. Is this essentially what an REST api does? Am I better off trying to use Piston, TastyPie, or Django-REST?
Django query api is chainable, so you can do this: