Search code examples
tastypie

How can I distinguish a detail or list REST method in tastypie


How can I find out if a GET method is requesting a detailed resource (example.com/api/v1/entry/1/) or a listing (example.com/api/v1/entry/)

What I am trying to do is to record how many times a detail GET method is called.

An option is to inspect the request object and get the PATH and see if a resource id was provided. However, I want to know if there's a better way to do this using tastypie's methods.


Solution

  • Override method get_detail.

    def get_detail(self, request, **kwargs):
        # Your custom code for incrementing GET counter
        return super(YourResource, self).get_detail(request, **kwargs)
    

    That method is called every time the get details method is requested.