Get list of unresponsive objects with tastypie Resource

I just want to use the get_list method that can return a list of objects, not HttpResponse, and without the format = json parameter.

I know about how to get data from a resource via a package like this:

 resource = MyResource()                                           
 request_bundle = resource.build_bundle(request)                   
 queryset = resource.obj_get_list(request_bundle)                  

 bundles = []                                                      
 for obj in queryset:                                              
     bundle = resource.build_bundle(obj=obj, request=request)      
     bundles.append(resource.full_dehydrate(bundle, for_list=True))
 objects = [ for b in bundles]    


get_list works great, but I need to create my own response rendering template and get_list is in = format.

but it returns all objects instead of 20


source to share

1 answer

If you want to return 20 items.

queryset = resource.obj_get_list(request_bundle)[:20]


P / s: Thanks for the code - this is what I'm looking for.



All Articles