I have a Django application which I am writing an API for using Tastypie. I have an endpoint created which calls the code:
class CollectionModelResource(ModelResource):
"""API to retireve ObjInCollection for a specific collection
"""
class Meta:
allowed_methods = ['get', 'put']
authentication = ApiKeyAuthentication()
authorization = Authorization()
queryset = ObjInCollection.objects.filter(collection__collection='mycollection1')
resource_name = 'objects'
This works well to return all those database records with collection='mycollection1'
. However, I would like to pass this mycollection1
value in via the querystring of the request. Yet I can't seem to find an exposed request object within this Meta
class.
Is there a way to get the request
object from the Meta
class inside a ModelResource
of Tastypie???
Tastypie does not allow this, but you can solve your problem in another way. You should create a custom build_filters()
method which allows you to filter the queryset before processing a request see [docs][1].