title: Django Rest API. Get all data from different models in a single API call
body: <p>I am trying to get all data related to model Post using one single API call. This call should include post contents, comments, upvote and downvotes.</p>
  <p>I have 4 models and Post model is a foreign key to every other model.</p>
  <pre><code>class Post(models.Model):
      title = models.CharField(max_length=200, null=True, blank=True)
      body = models.CharField(max_length=500, null=True, blank=True)
  
      def __str__(self):
          return str(self.title)
  
  
  class UpVote(models.Model):
      post = models.OneToOneField(Post, related_name=&quot;upvote_post&quot;, on_delete=models.CASCADE)
      upvotes = models.IntegerField(default=0)
  
  
  class DownVote(models.Model):
      post = models.OneToOneField(Post, related_name=&quot;downvote_post&quot;, on_delete=models.CASCADE)
      downvotes = models.IntegerField(default=0)
  
  
  class Comment(models.Model):
      post = models.ForeignKey(Post, related_name=&quot;comment_post&quot;, on_delete=models.CASCADE)
      comment = models.CharField(max_length=200, null=True, blank=True)
  </code></pre>
  <p>I saw this solution in a post to combine data with a foreign key relationship that exists.</p>
  <pre><code>class UpVoteSerializer(serializers.ModelSerializer):
      class Meta:
          model = UpVote
          fields = &quot;__all__&quot;
  
  
  class DownVoteSerializer(serializers.ModelSerializer):
      class Meta:
          model = DownVote
          fields = &quot;__all__&quot;
  
  
  class CommentSerializer(serializers.ModelSerializer):
      class Meta:
          model = Comment
          fields = &quot;__all__&quot;
  
  
  class PostSerializer(serializers.ModelSerializer):
      upvote = UpVoteSerializer(read_only=True, many=False)
      downvote = DownVoteSerializer(read_only=True, many=False)
      comments = CommentSerializer(read_only=True, many=True)
  
      class Meta:
          model = Post
          fields = (&quot;id&quot;, &quot;title&quot;, &quot;body&quot;, &quot;upvote&quot;, &quot;downvote&quot;, &quot;comments&quot;)
  </code></pre>
  <p>This is from the views.py file</p>
  <pre><code>@api_view(['GET'])
  def postList(request):
      post = Post.objects.all().order_by('-id')
      serializer = PostSerializer(post, many=True)
      return Response(serializer.data)
  </code></pre>
  <p>This is the output that get returned</p>
  <pre><code>[
      {
          &quot;id&quot;: 7,
          &quot;title&quot;: &quot;1st post&quot;,
          &quot;body&quot;: &quot;Body of 1st post&quot;
      },
      {
          &quot;id&quot;: 6,
          &quot;title&quot;: &quot;2nd post&quot;,
          &quot;body&quot;: &quot;Body of 2nd post&quot;
      },
      {
          &quot;id&quot;: 5,
          &quot;title&quot;: &quot;3rd post&quot;,
          &quot;body&quot;: &quot;Body of 3rd post&quot;
      },
      {
          &quot;id&quot;: 4,
          &quot;title&quot;: &quot;4th post&quot;,
          &quot;body&quot;: &quot;Body of 4th post&quot;
      }
  ]
  </code></pre>
  <p>I don't know why it's not returning back the comments and the upvotes and downvotes.</p>