File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 55from rest_framework import serializers
66from rest_framework .views import Response
77from rest_framework .pagination import PageNumberPagination , LimitOffsetPagination
8- from rest_framework .templatetags . rest_framework import replace_query_param
8+ from rest_framework .utils . urls import remove_query_param , replace_query_param
99
1010
1111class PageNumberPagination (PageNumberPagination ):
@@ -66,17 +66,18 @@ def get_last_link(self):
6666 url = replace_query_param (url , self .limit_query_param , self .limit )
6767
6868 offset = self .count - self .limit
69+
70+ if offset <= 0 :
71+ return remove_query_param (url , self .offset_query_param )
72+
6973 return replace_query_param (url , self .offset_query_param , offset )
7074
7175 def get_first_link (self ):
7276 if self .count == 0 :
7377 return None
7478
7579 url = self .request .build_absolute_uri ()
76- url = replace_query_param (url , self .limit_query_param , self .limit )
77-
78- offset = 0
79- return replace_query_param (url , self .offset_query_param , offset )
80+ return remove_query_param (url , self .offset_query_param )
8081
8182 def get_paginated_response (self , data ):
8283 return Response ({
You can’t perform that action at this time.
0 commit comments