Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get request parameters in Tastypie

I am building a REST API for my application that uses a NoSQL db (Neo4j) using Tastypie.

So I overrode some main methods of the class tastypie.resources.Resource to do so, and currently struggling to implement def obj_get_list(self, request=None, **kwargs): which is supposed to return a list of objects.

Actually, I want to pass a parameter to this method through the url (something like http://127.0.0.1:8000/api/airport/?query='aQuery' ) and then perform a query based on this parameter.

The problem is that the request is None so I can't get its parameter !

When printing the kwargs variable, I see this :

{'bundle': <Bundle for obj: '<testNeo4Django.testapp.api.Airport object at 0x9d829ac>' and with data: '{}'>}

Thanks for your help

like image 508
Anas Avatar asked Dec 27 '22 02:12

Anas


1 Answers

Currently positional argument request is not passed toobj_get_list.

So you should:

def obj_get_list(self, bundle, **kwargs):

    param =  bundle.request.GET['param']
    #fetch objects based on param
    return objects
like image 56
Pawel Furmaniak Avatar answered Jan 02 '23 03:01

Pawel Furmaniak