title: Django Rest update many to many by id
body: <p>I'm novice in python and django rest. But I'm confused. What is the best way to update many to many relation in django rest framework. 
  I read the docs 
  <a href="http://www.django-rest-framework.org/api-guide/relations/#manytomanyfields-with-a-through-model" rel="noreferrer">http://www.django-rest-framework.org/api-guide/relations/#manytomanyfields-with-a-through-model</a>
  By default, relational fields that target a ManyToManyField with a through model specified are set to read-only.</p>
  
  <p>If you explicitly specify a relational field pointing to a ManyToManyField with a through model, be sure to set read_only to True.</p>
  
  <p>So if I have a code </p>
  
  <pre><code>class Master(models.Model):
      # other fields  
      skills = models.ManyToManyField(Skill)
  
  class MasterSerializer(serializers.ModelSerializer):
      skills = SkillSerializer(many=True, read_only=False)
  </code></pre>
  
  <p>This will return skills as list of objects. And I don't have a way to update them. As far as I understood Django prefers work with objects vs object id when it comes to M2M. If I work with yii or rails I will work with "through" models. I would like to get skill_ids field. That I could read and write. And I can do this for write operation</p>
  
  <pre><code>class MasterSerializer(serializers.ModelSerializer):
      skill_ids = serializers.ListField(write_only=True)
  
      def update(self, instance, validated_data):
  
      # ...
      validated_data['skill_ids'] = filter(None, validated_data['skill_ids'])
      for skill_id in validated_data['skill_ids']:
          skill = Skill.objects.get(pk=skill_id)
          instance.skills.add(skill)
  
      return instance
  </code></pre>
  
  <p>But I cannot make it return skill_ids in field. And work for read and write operations. </p>