title: Django Rest Framework serialize additional fields from intermediate model
body: <p>I am developing a small application that lists the customers of a store. I'm trying to retrieve the additional fields of the intermediate model because a contact can belong to several stores but depending on the store it is premium or not and if he is happy or not.</p>
  
  <p>Here's the JSON response I'd like to get for a Store like <strong>/contacts/?store=my_store</strong></p>
  
  <pre><code>[
      {
          "id": "UX",
          "first_name": "UX",
          "last_name": "UX",
          "email": null,
          "mobile": null,
          "happy": True,
          "premium": True
      },
      {
          "id": "AX",
          "first_name": "AX",
          "last_name": "AX",
          "email": null,
          "mobile": null,
          "happy": False,
          "premium": True
      }
  ]
  </code></pre>
  
  <p>here are my models:</p>
  
  <pre><code>class Store(BaseModel):
      id = models.CharField(primary_key=True, max_length=200)
      name = models.CharField(max_length=100)
  
  
  class Contact(BaseModel):
      id = models.CharField(primary_key=True, max_length=200)
      first_name = models.CharField(max_length=100, null=True, blank=True)
      last_name = models.CharField(max_length=100, null=True, blank=True)
      email = models.CharField(max_length=100, null=True, blank=True)
      mobile = models.CharField(max_length=100, null=True, blank=True)
      stores = models.ManyToManyField(
          Store, through="MemberShip", through_fields=("contact", "store")
      )
  
  
  class MemberShip(BaseModel):
      contact = models.ForeignKey(
          Contact, on_delete=models.CASCADE, related_name="contact_to_store"
      )
      store = models.ForeignKey(
          Store, on_delete=models.CASCADE, related_name="store_to_contact"
      )
      happy = models.BooleanField(default=True)
      premium = models.BooleanField(default=False)
  </code></pre>
  
  <p>and my serializers:</p>
  
  <pre><code>class MemberShipSerializer(serializers.ModelSerializer):
      class Meta:
          model = MemberShip
          fields = ("contact", "store", "happy", "premium")
  
  
  class StoreSerializer(serializers.ModelSerializer):
      class Meta:
          model = Store
          fields = ("id", "name")
  
  
  class ContactSerializer(serializers.ModelSerializer):
      infos = MemberShipSerializer(
          source="contact_to_store" many=True, read_only=True
      )
  
      class Meta:
          model = Contact
          fields = (
              "id", "first_name", "last_name", "email", "mobile", "infos"
          )
  </code></pre>
  
  <p>As you can see, I first tried to gather all the information of the intermediate model in a field before displaying <strong>happy</strong> and <strong>premium</strong> but, strangely enough, the <strong>infos</strong> field is returned with an empty array value.
  Python v 3.7
  Django v 2.1
  DRF v 3.9</p>