I am using this class to return content-range value in the header, but when 
my client receives the response the headers are always empty and do not 
include the content-range


class ContentRangeHeaderPagination(pagination.PageNumberPagination):
    """
    A custom Pagination class to include Content-Range header in the
    response.
    """

    def get_paginated_response(self, data):
        """
        Override this method to include Content-Range header in the 
response.

        For eg.:
        Sample Content-Range header value received in the response for 
        items 11-20 out of total 50:

                Content-Range: items 10-19/50
        """

        total_items = self.page.paginator.count # total no of items in 
queryset
        item_starting_index = self.page.start_index() - 1 # In a page, 
indexing starts from 1
        item_ending_index = self.page.end_index() - 1

        content_range = 'items {0}-{1}/{2}'.format(item_starting_index, 
item_ending_index, total_items)      

        headers = {'content-range': content_range }
        
        return Response(OrderedDict([
            ('items', data)
        ]), headers=headers)

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to