-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import typing | ||
|
||
from rest_framework.pagination import LimitOffsetPagination | ||
from rest_framework.response import Response | ||
|
||
|
||
class LimitOffsetPaginationExtended(LimitOffsetPagination): | ||
""" | ||
Extend LimitOffsetPagination to customise the default response. | ||
For example: | ||
## Default response | ||
{ | ||
"count": 1, | ||
"next": null, | ||
"previous": null, | ||
"results": [{ | ||
"id": 6, | ||
"inserted_at": "2021-01-26T21:13:35.477879Z", | ||
"expires_at": null, | ||
"active": false, | ||
"user": 1, | ||
"actor": 2, | ||
"type": "warning", | ||
"reason": null, | ||
"hidden": false | ||
}] | ||
} | ||
## Required response | ||
[{ | ||
"id": 6, | ||
"inserted_at": "2021-01-26T21:13:35.477879Z", | ||
"expires_at": null, | ||
"active": false, | ||
"user": 1, | ||
"actor": 2, | ||
"type": "warning", | ||
"reason": null, | ||
"hidden": false | ||
}] | ||
""" | ||
|
||
default_limit = 100 | ||
|
||
def get_paginated_response(self, data: typing.Any) -> Response: | ||
"""Override to skip metadata i.e. `count`, `next`, and `previous`.""" | ||
return Response(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters