title: Django Rest Framework inserting and updating writable nested serializer
body: <p>I trying to insert and update a writable nested serializer with Django Rest Framework, following examples like <a href="https://stackoverflow.com/questions/28078092/django-rest-framework-writable-nested-serializers">this</a>. But it doesn't work, because somehow after I execute <strong><code>serializer.is_valid()</code></strong> it lose the reference from <strong><code>serializer.validated_data</code></strong> like if it never was sent.</p>
  
  <p>What could I having doing wrong?</p>
  
  <p>My models</p>
  
  <pre><code>class User(AbstractUser):
  
      institution = models.ForeignKey(Institution, on_delete=None, null=True, blank=True)
  
      class Meta:
          db_table = 'User'
          managed = True
          verbose_name = 'Users'
          verbose_name_plural = 'Users'
          ordering = ['id']
  
      def __str__(self):
          return self.email
  
  class Institution(models.Model):
      id = models.AutoField(db_column='id', primary_key=True)
      name = models.CharField(db_column='name', max_length=255, null=False)
      country = models.CharField(db_column='country', max_length=255, null=False)
  
      class Meta:
          db_table = 'Institution'
          managed = True
          verbose_name = 'Institutions'
          verbose_name_plural = 'Institutions'
          ordering = ['id']
  
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>My serializers</p>
  
  <pre><code>class InstitutionSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Institution
          fields = '__all__'
          datatables_always_serialize = ('id', 'name', 'country')
  
  class UserSerializer(serializers.HyperlinkedModelSerializer):
      institution = InstitutionSerializer()
  
      def create(self, validated_data):
          return User.objects.create_user(**validated_data)
  
      def update(self, instance, validated_data):
          institution_data = validated_data['institution']
          instance.institution = Institution.objects.get(pk=institution_data['id'])
          return instance
  
      class Meta:
          model = User
          fields = (
              'id',
              'username',
              'first_name',
              'last_name',
              'email',
              'password',
              'is_active',
              'institution',
          )
          datatables_always_serialize = (
              'id',
              'username',
              'first_name',
              'last_name',
              'email',
              'is_active',
              'institution',
          )
  </code></pre>
  
  <p>My view</p>
  
  <pre><code>class UserViewSet(ModelViewSet):
      serializer_class = UserSerializer
      permission_classes = (IsSuperUserPermission,)
  
      def list(self, request, **kwargs):
          params = Q()
          if 'search[value]' in request.GET and request.GET['search[value]'] != '':
              params = Q(username__icontains=request.GET['search[value]']) |\
                       Q(first_name__icontains=request.GET['search[value]']) |\
                       Q(last_name__icontains=request.GET['search[value]']) |\
                       Q(email__icontains=request.GET['search[value]']) |\
                       Q(institution__name__icontains=request.GET['search[value]'])
  
          queryset = User.objects.filter(params).select_related().order_by('id')
          serializer = self.serializer_class(queryset, many=True)
          return Response(serializer.data)
  
      def retrieve(self, request, *args, **kwargs):
          queryset = User.objects.filter(pk=request.GET['pk']).select_related()
          serializer = UserSerializer(queryset, many=True)
          return Response(serializer.data)
  
      def get_permissions(self):
          if self.action in ('create',):
              self.permission_classes = [AllowAny, ]
          return super(self.__class__, self).get_permissions()
  
      def create(self, request, *args, **kwargs):
          serializer = UserSerializer(data=request.data)
          if serializer.is_valid():
              serializer.create(serializer.validated_data)
              return Response(serializer.data)
          else:
              return Response(serializer.errors, status.HTTP_500_INTERNAL_SERVER_ERROR)
  
      def partial_update(self, request, *args, **kwargs):
          user = User.objects.get(pk=request.data['id'])
          serializer = UserSerializer(instance=user, data=request.data, partial=True)
          if serializer.is_valid():
  
              if 'password' in serializer.validated_data:
                  serializer.validated_data['password'] = make_password(serializer.validated_data['password'])
  
              serializer.update(user, serializer.validated_data)
              return Response(serializer.data)
          else:
              return Response(serializer.errors, status.HTTP_500_INTERNAL_SERVER_ERROR)
  </code></pre>
  
  <p>Edit.</p>
  
  <p>I submitting data like this: </p>
  
  <pre><code>{
      "username": "BLA",
      "email": "BLA@BLA.com",
      "first_name": "BLA",
      "last_name": "BLA",
      "institution": 1,
      "is_active": true,
      "password": "bla12345"
  }
  </code></pre>