How to update Django Rest User attribute?
<p>I have this model:</p>

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

    user = models.OneToOneField(User, related_name='profile')
    stuff = models.TextField(default='')

User.profile = property(UserProfile)
</code></pre>

<p>With this serializer:</p>

<pre><code>class UserProfileSerializer(UserSerializer):

    stuff = serializers.SerializerMethodField()

    def get_stuff(self, obj):
        return obj.profile.stuff

    def update(self, instance, validated_data):
        instance.profile.stuff = validated_data.get('stuff', instance.profile.stuff)
        instance.save()
        return instance
</code></pre>

<p>With this endpoint:</p>

<pre><code>class UpdateUserProfile(UpdateAPIView):

    model = UserProfile
    serializer_class = UserProfileSerializer
    permission_classes = [permissions.IsAuthenticated]

    def get_object(self):
        return self.request.user
</code></pre>

<p>When I call HTTP/PUT to update my stuff field, it doesn't update. I don't know why.</p>

<p>if your update method is executing and you are getting instance.profile in the method. The Issue happens at </p>

<pre><code>instance.profile.stuff = validated_data.get('stuff', instance.profile.stuff)
instance.save()
</code></pre>

<p>you need to update the profile instance. </p>

<pre><code>instance.profile.stuff = validated_data.get('stuff', instance.profile.stuff)
instance.profile.save()
</code></pre>

<p>"instance.profile.save()" Will update your profile instance.</p>

python django rest django-rest-framework