title: How to apply pagination in this case (Django Rest Framework)?
body: <p>I built a simple social media application. Users can post two types of posts Blog and Carousel. Users can follow other users, you can see other users posts if you follow them.</p>
  <p>So, while implementing the home page API (home page consists of both blog and carousel posts of people you follow) i filter out the  blog and carousel like this.</p>
  <pre><code>blogposts = BlogPost.objects.filter(
              Q(author__profile__in=request.user.profile.followings.all())
              | Q(author=request.user)
          )
  
  carouselposts = Carousel.objects.filter(
              Q(author__profile__in=request.user.profile.followings.all())
              | Q(author=request.user)
          )
  </code></pre>
  <p>It basically filters all  blogs and carousel of the people you follow and return it after applying suitable serializers.</p>
  <p>But the problem is when the page is loaded, if a user has got 100 posts in his home page all of them are loaded at once. Instead i only wany to load 10 recent posts in the beginning and keep loading next 10 recent posts when user reaches the bottom of the home page.</p>
  <p>Since there are two tables here Blogpost and Carousel i don't how to paginate this.</p>
  <p>Also, one more question? If i somehow paginate this content to send 10 recent posts at once, will it be internally querying only 10 posts at each request or will it query all 100 posts at once and send them in chunks of 10?</p>
  <p>Here is the complete code for home page API.</p>
  <pre><code>
  class HomepageBlogPostView(APIView):
      permission_classes = [permissions.IsAuthenticated]
  
      def get(self, request):
  
          blogposts = BlogPost.objects.filter(
              Q(author__profile__in=request.user.profile.followings.all())
              | Q(author=request.user)
          )
          posts_list_serializer = BlogPostSerializer(
              blogposts, many=True, context={&quot;request&quot;: request}
          )
  
          carouselposts = Carousel.objects.filter(
              Q(author__profile__in=request.user.profile.followings.all())
              | Q(author=request.user)
          )
  
          carousels_list_serializer = CarouselSerializer(
              carouselposts, many=True, context={&quot;request&quot;: request}
          )
  
          blogposts_list = list(posts_list_serializer.data)
          carousels_list = list(carousels_list_serializer.data)
  
          blogposts_list.extend(carousels_list)
          posts = blogposts_list
          posts.sort(key=lambda post: -post[&quot;published&quot;])
  
          return Response(posts, status=status.HTTP_200_OK)
  </code></pre>