title: django rest framework return a custom object using ModelSerializer and ModelViewSet
body: <p>I have three models, three serializers, one modelviewset below.
  I am using django-rest-framework to make a rest api for android.</p>
  
  <p>The restaurant model was created first. Then I created a star model and an image model.</p>
  
  <p>What I want to do is to add star and image objects into restaurant objects.</p>
  
  <p>finally I've got what I want result but I think my viewset code looks like wrong..</p>
  
  <p>Is there another way not to use "for loop"?</p>
  
  <p>Models</p>
  
  <pre><code>class Restaurant(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(max_length=255)
      address = models.CharField(max_length=255)
      category = models.ForeignKey(Category, on_delete=models.CASCADE)
      weather = models.ForeignKey(Weather, on_delete=models.CASCADE)
      distance = models.ForeignKey(Distance, on_delete=models.CASCADE)
      description = models.TextField('DESCRIPTION')
  
      def __str__(self):
          return self.name
  
  class Star(models.Model):
      restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      rating = models.IntegerField('RATING')
  
      def __str__(self):
          return self.restaurant
  
  
  class RestaurantImage(models.Model):
      id = models.AutoField(primary_key=True)
      restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)
      path = models.CharField(max_length=255)
  </code></pre>
  
  <p>Serializer</p>
  
  <pre><code>class StarSerializer(serializers.ModelSerializer):
      class Meta:
          model = Star
          fields = ('id', 'restaurant', 'user', 'rating', )
  
  
  class RestaurantDetailSerializer(serializers.ModelSerializer):
      category = CategorySerializer()
      weather = WeatherSerializer()
      distance = DistanceSerializer()
  
      class Meta:
          model = Restaurant
          fields = ('id', 'name', 'address', 'category', 'weather',
                    'distance', 'description', )
  
  
  class ImageSerializer(serializers.ModelSerializer):
      class Meta:
          model = RestaurantImage
          fields = ('id', 'path', 'restaurant')
  </code></pre>
  
  <p>ViewSet</p>
  
  <pre><code>class RestaurantDetailInfoViewSet(viewsets.ModelViewSet):
      queryset = Restaurant.objects.all()
      serializer_class = RestaurantSerializer
  
      def list(self, request, *args, **kwargs):
          restaurant_list = Restaurant.objects.all()
          restaurant_result = []
          for restaurant in restaurant_list:
              restaurantInfo = Restaurant.objects.filter(id=restaurant.pk)
              restaurant_serializer = RestaurantDetailSerializer(restaurantInfo, many=True)
              ratingAverageValue = Star.objects.filter(restaurant=restaurant.pk).aggregate(Avg('rating'))
              images = RestaurantImage.objects.filter(restaurant=restaurant.pk)
              image_serializer = ImageSerializer(images, many=True)
  
              restaurant_dic = {
                  'restaurant': restaurant_serializer.data,
                  'ratingAverage': ratingAverageValue['rating__avg']
                  if ratingAverageValue['rating__avg'] is not None else 0,
                  'images': image_serializer.data
              }
              restaurant_result.append(restaurant_dic)
  
          return Response(restaurant_result)
  </code></pre>
  
  <p>Result</p>
  
  <pre><code>[
  {
      "restaurant": [
          {
              "id": 1,
              "name": "restaurant1",
              "address": "address1",
              "category": {
                  "c_id": 1,
                  "name": "foodtype1"
              },
              "weather": {
                  "w_id": 1,
                  "name": "sunny"
              },
              "distance": {
                  "d_id": 1,
                  "name": "inside"
              },
              "description": "description1"
          }
      ],
      "ratingAverage": 2.6667,
      "images": [
          {
              "id": 1,
              "path": "imagepath",
              "restaurant": 1
          }
      ]
  },
  </code></pre>