[Answered ]-Is it possible to generically access the response object in a Django Rest Framework ModelViewSet?

2👍

As per sagarchalise’s suggestion that I simply override Django’s dispatch method, this works:

class UnCachedModelViewSet(viewsets.ModelViewSet):

    def dispatch(self, *args, **kwargs):
        response = super(UnCachedModelViewSet, self).dispatch(*args, **kwargs)
        response['Cache-Control'] = 'no-cache'
        return response

class EntityViewSet(UnCachedModelViewSet):
    queryset = Company.objects.all().order_by('name')
    //no need to override each action now
👤John

Leave a comment