I created an API with the Django Rest Framework. I want to change the pagination to improve the user interface.
Problem :
The client addresses all requests. The request looks like this:
http://website.com/api/v1/posts/?page=1
This returns the first page of messages. However, new posts are always being created. Therefore, when the user requests:
http://website.com/api/v1/posts/?page=2
Posts almost always coincide with pages 1 (since new data always arrives and we order -created).
Possible Solution?
I had an idea to send the identifier of the object along with the request so that when capturing messages. We take them in relation to the last request.
http://website.com/api/v1/posts/?page=2&post_id=12345
And when we paginate, we filter where post_id < 12345
But this only works if our post_id is an integer.
ListAPIView
class PostList(generics.ListAPIView):
"""
API endpoint that allows posts to be viewed
"""
serializer_class = serializers.PostSerializer
model = Post
? .