title: Serializing Many To Many intermediate table in Django Rest Framework
body: <p>I would like to learn how to get many to many intermediate table's serializer data by whole <code>model</code> , not only by id.</p>
  
  <pre><code>#this is my model class
  class ProductMaterial(models.Model):
      product = models.ForeignKey(Product, on_delete=models.CASCADE)
      material = models.ForeignKey(Material, on_delete=models.CASCADE)
      material_rate = models.FloatField(blank=True, null=True)
      material_price = models.FloatField(blank=True, null=True)
  
  
  
  #serializer
  class ProductMaterialSerializer(serializers.ModelSerializer):
         class Meta:
             model = ProductMaterial
             fields = '__all__'
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>    {
          "id": 1,
          "material_rate": 0.3,
          "material_price": 6.7,
          "product": 186,
          "material": 7
      },
     {
          "id": 2,
          "material_rate": 0.7,
          "material_price": 1.7,
          "product": 186,
          "material": 8
      },
  </code></pre>
  
  <h1>Problems:</h1>
  
  <ol>
  <li>First problem is it duplicates data because of many to many table</li>
  <li>I want to see my <code>product</code> and <code>material</code> model fields too.</li>
  </ol>
  
  <h1>My target:</h1>
  
  <pre><code>{
      "id": 1,
      "product": {
                   "name" : "abcd",
                   "date" : "01.01.2018"
  
                  },
      "material": [
                    {
                       "id" : 7,
                       "material_rate" : 0.3,
                       "material_price" : 6.7,
  
                    },
                    {
                       "id" : 8,
                       "material_rate" : 0.7,
                       "material_price" : 1.7,
  
                    },
                 ]
  },
  </code></pre>
  
  <h1>Solution 2:</h1>
  
  <p>I have implemented this solution -> <a href="https://stackoverflow.com/a/45834689/5491260">https://stackoverflow.com/a/45834689/5491260</a>
  and it helped me.</p>