Skip to content

Commit 0dd80d7

Browse files
committed
Fixed pagination data
1 parent 9f88386 commit 0dd80d7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

‎rest_framework_json_api/pagination.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pagination fields
33
"""
44
# pylint: disable=no-init, too-few-public-methods, no-self-use
5-
5+
from collections import OrderedDict
66

77
from rest_framework import serializers
88
from rest_framework import pagination
@@ -108,6 +108,7 @@ class PageNumberPagination(BasePagination):
108108
"""
109109
An Ember (soon to be json-api) compatible pagination format
110110
"""
111+
111112
def build_link(self, index):
112113
if not index:
113114
return None
@@ -126,16 +127,18 @@ def get_paginated_response(self, data):
126127
return Response({
127128
'results': data,
128129
'meta': {
129-
'pagination': {
130-
'page': self.page.number,
131-
'count': self.page.paginator.count,
132-
'total': self.page.paginator.num_pages,
133-
}
130+
'pagination': OrderedDict([
131+
('page', self.page.number),
132+
('count', self.page.paginator.count),
133+
('total', self.page.paginator.num_pages),
134+
('start_index', self.page.start_index() - 1),
135+
('end_index', self.page.end_index() - 1),
136+
])
134137
},
135-
'links': {
136-
'first': self.build_link(self.page.start_index()),
137-
'last': self.build_link(self.page.end_index()),
138-
'next': self.build_link(next),
139-
'prev': self.build_link(previous),
140-
}
138+
'links': OrderedDict([
139+
('first', self.build_link(1)),
140+
('last', self.build_link(self.page.paginator.num_pages)),
141+
('next', self.build_link(next)),
142+
('prev', self.build_link(previous))
143+
])
141144
})

0 commit comments

Comments
 (0)