From dd4fdcc418af949b3f44dbea7868af3624a4cfba Mon Sep 17 00:00:00 2001 From: Payam Date: Sat, 17 Jun 2017 09:51:53 +0100 Subject: [PATCH] Update pagination.py Allow User to add extra fields to data before sending it to HTTP Response --- rest_framework/pagination.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 0255cfc7f..3f937ab66 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -225,13 +225,16 @@ class PageNumberPagination(BasePagination): self.request = request return list(self.page) - def get_paginated_response(self, data): - return Response(OrderedDict([ + def get_paginated_dictionary(self, data): + return OrderedDict([ ('count', self.page.paginator.count), ('next', self.get_next_link()), ('previous', self.get_previous_link()), ('results', data) - ])) + ]) + + def get_paginated_response(self, data, extra_fields={}): + return Response(self.get_paginated_dictionary(data).update(extra_fields)) def get_page_size(self, request): if self.page_size_query_param: