title: Django Rest Framework Serializer : get fields of two models
body: <p>Hello all been working on Rest API for couple of weeks I have learned about serializers and nested serializer. I am stucked on grabbing fields from Two models is it possible to do in serializer. Here is my code.</p>
  <pre><code>class Slider(BaseModel):
      page = models.ForeignKey(Page, on_delete=models.CASCADE)
  
      section = models.CharField(
          max_length=20,
          validators=[validators.validate_section_name],
          )
  
      tag = models.CharField(
          max_length=20,
          validators=[validators.validate_tag_name],
          )
  
      class Meta:
          default_permissions = ()
          verbose_name = 'Slider'
          verbose_name_plural = 'Sliders'
  
      def __str__(self):
          return self.section
  </code></pre>
  <p>next model I want to combine in serializer is</p>
  <pre><code>class SliderImage(BaseModel):
      image = models.ImageField(
          upload_to=upload_slider_image_to,
          validators=[],
          null=True, blank=True
      )
      slider = models.ForeignKey(Slider,
                                 on_delete=models.CASCADE,
                                 related_name='slider_image',
                                 )
  
      class Meta:
          default_permissions = ()
          verbose_name = 'Slider Image'
          verbose_name_plural = 'Slider Images'
  </code></pre>
  <p>now is there any way out so that i can get serializers in this way?</p>
  <p>expected serializer is as</p>
  <pre><code>&quot;sliders&quot;: [
        {
          &quot;images&quot;: [
            &quot;http://34.202.219.142:8000/media/promotion/slider/slider_56cc1829-aa78-40e3-9163-2c7297358de0.png&quot;,
            &quot;http://34.202.219.142:8000/media/promotion/slider/slider_4ea6d488-a1f6-4a0a-b522-ae0285e482df.png&quot;,
            &quot;http://34.202.219.142:8000/media/promotion/slider/slider_29862eb0-7a2a-4cc4-90b0-3ec5de510d75.png&quot;
          ],
          &quot;section&quot;: &quot;bus company&quot;,
          &quot;tag&quot;: &quot;hot-deals&quot;
        },
  </code></pre>
  <p>I tried this in serializers</p>
  <pre><code>class SliderSerializers(serializers.ModelSerializer):
      class Meta:
          model = Slider
          fields = '__all__'
  
  
  class ListSliderSerializer(SliderSerializers):
      class Meta(SliderSerializers.Meta):
          fields = (
  
              'section',
              'tag',
          )
  
  
  class GetHomePagePromotionSerializer(serializers.Serializer):
      sliders = ListSliderSerializer(many=True, read_only=True)
  </code></pre>
  <p>I am serializing in following way in usecases.py and views.py as</p>
  <p>#usecases</p>
  <pre><code>class GetHomePagePromotionUseCase(BaseUseCase):
      def execute(self):
          self._factory()
          return self._home_page_promotion
  
      def _factory(self):
          self._home_page_promotion = {
              'sliders': self.list_home_sliders(),
              
          }
  
      def list_home_sliders(self):
          return SliderImage.objects.all()
  
      
  </code></pre>
  <p>#views.py</p>
  <pre><code>class GetHomePagePromotionView(generics.RetrieveAPIView):
      &quot;&quot;&quot;
      Use this end-point to get promotion items for the home page
      &quot;&quot;&quot;
      serializer_class = GetHomePagePromotionSerializer
  
      def get_object(self):
          return GetHomePagePromotionUseCase().execute()
  </code></pre>
  <p>I am newbie hope I clarified my question.</p>