title: How to get complete list of related objects in Django-rest-Framework
body: <p>I am trying to implement Nested serializer for the first time in django-rest-framework
  My requirement is i need the response data in below form :-</p>
  <pre><code>{
  id: 0,
  title: &quot;Fresh&quot;,
  data: [
      [{
              image: &quot;.../assets/images/banana.jpeg&quot;,
              name: &quot;Fruits&quot;,
              image_scaling: 2,
              API: &quot;http://database_api&quot;
          },
          {
              image: &quot;../assets/images/banana.jpeg&quot;,
              name: &quot;Vegetables&quot;,
              image_scaling: 2,
              API: &quot;http://database_api&quot;
          },
          {
              image: &quot;../assets/images/banana.jpeg&quot;,
              name: &quot;Exotic Vegetables&quot;,
              image_scaling: 2,
              API: &quot;http://database_api&quot;
          }
      ]
  ]
  
  }
  </code></pre>
  <p>I am validating the token for the get api and listing the objects form DB.
  My current implementation of views.py is :-</p>
  <pre><code>class home(APIView):
  
   def get(self,request,format=None):
  
      header_token = request.META.get('HTTP_AUTHORIZATION', None)
      if header_token is not None:
  
          token = header_token
          access_token=token.split(' ')[1]
          print(access_token)
      
      if(validate_token(access_token) == None):
          raise NotFound('user does exist')
          
  
      queryset=Fresh.objects.all().select_related('data')
      print(queryset)
      serializer = FreshSerializer(queryset,many=True)
    
      return Response(serializer.data)
  </code></pre>
  <p>Serializer.py is :-</p>
  <pre><code>class DataSerializer(serializers.ModelSerializer):
     class Meta:
      model=data
      fields = ('name','image_scaling','image')
  
  class FreshSerializer(serializers.ModelSerializer):
     data=DataSerializer(read_only=True, many=False)
     class Meta:
        model = Fresh
        fields = ('title','data')
  </code></pre>
  <p>models.py is :-</p>
  <pre><code>class data(models.Model):
    name=models.CharField(max_length=9,null=True)
    image_scaling=models.IntegerField(default=0,null=True)
    image=models.URLField(max_length = 200)
  def __str__(self):
      return str(self.name)
  
  class Fresh(models.Model):
     title=models.CharField(max_length=9)
     data=models.ForeignKey(data,on_delete=models.CASCADE,default=None, null=True)
  def __str__(self):
      return str(self.title)+&quot; &quot; +str(self.data)
  </code></pre>
  <p>My current output is :-</p>
  <pre><code>[
  {
      &quot;title&quot;: &quot;vegetable&quot;,
      &quot;data&quot;: {
          &quot;name&quot;: &quot;vegetable&quot;,
          &quot;image_scaling&quot;: 2,
          &quot;image&quot;: &quot;https......jpg&quot;
      }
  },
  {
      &quot;title&quot;: &quot;exoticveg&quot;,
      &quot;data&quot;: {
          &quot;name&quot;: &quot;exoticveg&quot;,
          &quot;image_scaling&quot;: 2,
          &quot;image&quot;: &quot;https://.......jpg&quot;
      }
  } ]
  </code></pre>
  <p>I was trying to do by listapiview and modelviewset, but i am not able to get the desired output.I have seen similar queries in stack-overflow, but no solution seems to work for me.  I am not getting list of objects of foreign key , am i doing something wrong in my model or running wrong query? I am really stuck at it.
  How shall i go about it.
  Please help!!!</p>