Django rest framework nested serialization not working properly
<p>I have these serializers in my app:</p>

<pre><code>class ScheduleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Schedule
        fields = ('id',)

class DisciplineSerializer(serializers.ModelSerializer):
    class Meta:
        model = Discipline
        fields = ('id',)


class WriteTeacherSerializer(serializers.ModelSerializer):
    disciplines = DisciplineSerializer(many=True)
    schedules = ScheduleSerializer(many=True)
    class Meta:
        model = Teacher
        fields = ('phone_number', 'bio', 'price', 'disciplines', 'schedules')
        depth = 1

    def update(self, instance, validated_data):

        print "\n"
        #Debugging here
        print validated_data
        print "\n"
        print instance.__dict__
        print "\n"

        instance.phone_number = validated_data['phone_number']
        instance.bio = validated_data['bio']
        instance.price = validated_data['price']
        disciplines = validated_data.pop('disciplines')
        schedules = validated_data.pop('schedules')
        for discipline in disciplines:
            try:
                stored_discipline = Discipline.objects.get(id=discipline['id'])
                instance.disciplines.add(stored_discipline)
            except Discipline.DoesNotExist:
                raise Http404

        for schedule in schedules:
            try:
                stored_schedule = Schedule.objects.get(id=schedule['id'])
                instance.schedules.add(stored_discipline)
            except Discipline.DoesNotExist:
                raise Http404
        instance.save()
        return instance
</code></pre>

<p>As you can see I am trying a nested serialization with the fields <code>schedules</code> and <code>disciplines</code>. I think I followed the documentation, but the nested serialization is not working when I test it. I printed the <code>instance</code> and <code>validated_data</code> objects and tested it on the shell.</p>

<p>I start the data in this format:</p>

<pre><code>data = {u'phone_number': u'+99999999999', u'bio': u'BIO', u'price': 40, u'disciplines': [{'id': 1}], u'schedules': [{'id': 2}]}
</code></pre>

<p>I got a teacher instance and started the serializer like this:</p>

<pre><code>serializer = WriteTeacherSerializer(teacher, data=data)
</code></pre>

<p>It shows True on a <code>serializer.is_valid()</code> call.</p>

<p>However when I try to save it the <code>validated_data</code> and the <code>instance.__dict__</code> are like that:</p>

<pre><code>#validated_data
{u'phone_number': u'+5584998727770', u'bio': u'BIO', u'price': 40, u'disciplines': [OrderedDict()], u'schedules': [OrderedDict()]}


#instance.__dict__
{'phone_number': u'', 'bio': u'', 'price': 50, 'profile_id': 2, '_state': &lt;django.db.models.base.ModelState object at 0xb64a6bec&gt;, 'id': 6}
</code></pre>

<p>They don't seem to notice the nested fields wich makes the <code>update()</code> method not work.  </p>

<p>Am I doing something wrong?</p>

<p>Here is my Teacher Model as well:</p>

<pre><code>class Teacher(models.Model):

    price = models.IntegerField(default=50)
    phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Wrong phone number format.")
    phone_number = models.CharField(validators=[phone_regex], max_length=15, blank=True)
    profile = models.OneToOneField(Profile, on_delete=models.CASCADE)
    schedules = models.ManyToManyField(Schedule, related_name='schedules')
    disciplines = models.ManyToManyField(Discipline, related_name='disciplines')
    bio = models.CharField(max_length=200, blank=True)
</code></pre>