title: DRF use another model related fields in serializer
body: <p>I have 3 model <strong>Product</strong> - <strong>Peyment</strong> - <strong>ProductDiscountControll</strong></p>
  
  <p><code>Peyment</code> and <code>ProductDiscountControll</code> have relation to column "<code>product</code>" to <strong>Product</strong> table</p>
  
  <p>I want to have related ProductDiscountControll data like <code>discount</code> and <code>discount_code_precent</code> in peyment serilizer at get request.</p>
  
  <p>In quest to do that, I tried following code in my <code>Serializer</code> Class </p>
  
  <pre><code>def get_product_discount(self, obj):
      return obj.product.product_discount.discount
  </code></pre>
  
  <p>but server says :</p>
  
  <pre><code>Field name `product_discount` is not valid for model `Peyment`.
  </code></pre>
  
  <p>I also tried like this way:</p>
  
  <pre><code>product_discount = ProductDiscountControllSerializer(many=True,read_only=True)
  </code></pre>
  
  <p>but <code>product_discount</code> not available in result</p>
  
  <p>my view is look like this </p>
  
  <pre><code>class PeymentAPIView(APIView, mixins.DestroyModelMixin):
      permission_classes = [IsSafeGuard]
  
      def get(self, request):
          pay = Peyment.objects.filter(
              email=request.user.email,
              status=0,
  
          )
          serializer = PeymentSerializer(instance=pay, many=True)
          return Response(serializer.data)
  </code></pre>
  
  <p>this is related Serializer class for get request:</p>
  
  <pre><code>class PeymentSerializer(ModelSerializer):
      producttitle = serializers.SerializerMethodField()
  
      def get_producttitle(self, obj):
          return obj.product.title
  
      productprice = serializers.SerializerMethodField()
  
      def get_productprice(self, obj):
          return obj.product.price
  
  
      def get_discount(self, obj):
          return obj.product_discount.discount
      #product_discount = ProductDiscountControllSerializer(many=True,read_only=True)
  
  
      class Meta:
          model = Peyment
          fields = [
              'product',
              'id',
              'producttitle',
              'productprice',
              'discount',
              'status',
              'user',
              'email',
              'transfer_id',
              'created_date',
              'updated_date',
          ]
          read_only_fields = ['email', 'user', 'producttitle', 'productprice']
  </code></pre>
  
  <p>this is Product model:</p>
  
  <pre><code>class Product(models.Model):
      product_id = models.AutoField(primary_key=True)
      author = models.ForeignKey(User, on_delete=models.CASCADE, db_index=True)
      title = models.CharField(max_length=200)
      video_length = models.CharField(max_length=20, null=True, blank=True)
      mini_description = models.CharField(max_length=1000, null=True, blank=True)
      full_description = models.TextField(null=True, blank=True)
      you_need = models.CharField(max_length=1000, null=True)
      you_learn = models.CharField(max_length=2000, null=True)
      price = models.CharField(max_length=50, null=True, blank=True)
      video_level = models.CharField(max_length=100, null=True, blank=True)
      created_date = models.DateTimeField(auto_now_add=True)
      updated_date = models.DateTimeField(auto_now=True)
      image = models.FileField(upload_to=upload_to_custom_p,null=True,blank=True)
  </code></pre>
  
  <p>Peyment model:</p>
  
  <pre><code>class Peyment(models.Model):
      product = models.ForeignKey(Product, on_delete=models.CASCADE, to_field='product_id',
                                  related_name='product_peyment')
      status = models.CharField(max_length=30, null=True)
      user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
      transfer_id = models.CharField(max_length=100, null=True, blank=True)
      email = models.EmailField()
      created_date = models.DateTimeField(auto_now_add=True)
      updated_date = models.DateTimeField(auto_now=True)
  </code></pre>
  
  <p>and discount model:</p>
  
  <pre><code>class ProductDiscountControll(models.Model):
      product = models.OneToOneField(Product, on_delete=models.CASCADE, to_field='product_id',
                                  related_name='product_discount')
      discount = models.IntegerField(max_length=50, null=True, blank=True)
      discount_code = models.CharField(max_length=50, null=True, blank=True)
      discount_code_precent = models.CharField(max_length=80, null=True, blank=True)
      updated_date = models.DateTimeField(auto_now=True)
  </code></pre>
  
  <p>updated :</p>
  
  <pre><code># product peyment
  class PeymentSerializer(ModelSerializer):
      producttitle = serializers.SerializerMethodField()
  
      def get_producttitle(self, obj):
          return obj.product.title
  
      productprice = serializers.SerializerMethodField()
  
      def get_productprice(self, obj):
          return obj.product.price
  
      def get_discount(self, obj):
          serializer = ProductDiscountControllSerializer(obj.product.product_discount)
          return serializer.data
  
  
      class Meta:
          model = Peyment
          fields = [
              'product',
              'id',
              'producttitle',
              'productprice',
              'discount',
              'status',
              'user',
              'email',
              'transfer_id',
              'created_date',
              'updated_date',
          ]
          read_only_fields = ['email', 'user', 'producttitle', 'productprice']
  </code></pre>