title: Is there a way to dynamically specify a queryset for nested relationship (nested serializer class) in django rest framework
body: <p>Suppose we have two models:</p>
  <pre><code>class Chapter(models.Model):
      title = models.CharField(max_length=128)
      owner = models.ForeignKey(User, on_delete=models.CASCADE)
  
  
  class Post(models.Model):
      title = models.CharField(max_length=128)
      body = models.TextField()
      is_archived = models.BooleanField(default=False)
      chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE)
  </code></pre>
  <p>And default <code>ModelViewSet</code> viewset for <code>Chapter</code> model:</p>
  <pre><code>class ChapterViewSet(viewsets.ModelViewSet):
      queryset = Chapter.objects.all()
      serializer_class = ChapterSerializer
  </code></pre>
  <p>The key thing is that <code>ChapterSerializer</code> performs nested serialization using <code>PostSerializer</code> to provide a <code>post_set</code> key in the response.</p>
  <pre><code>class PostSerializer(serializers.HyperlinkedModelSerializer):
      detail_url = HyperlinkedIdentityField(view_name='post-detail', read_only=True)
  
      class Meta:
          fields = ['id', 'title', 'is_archived', 'detail_url']
          model = Post
  
  class ChapterSerializer(serializers.ModelSerializer):
      post_set = PostSerializer(read_only=True, many=True)
  
      class Meta:
          model = Chapter
          fields = ['id', 'title', 'owner', 'post_set']
  </code></pre>
  <p>The question is how I can dynamically specify a queryset for this nested <code>PostSerializer</code>. For example, when user makes <code>GET</code> request I only want to include the posts that are not archived (<code>is_archived</code> field is set to <code>False</code>) if user, who has done a request, is not an owner of a <code>Chapter</code> (<code>request.user != current_chapter.owner</code>). Is there any way to achive it?</p>