title: Update user profile and user in one request
body: <p>Thanks in advance for looking. </p>
  
  <p><strong>The goal:</strong></p>
  
  <p>In short: Update django user object and custom user profile object only if there is a change from a single view.</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>For starters, this is my first time trying to do anything like this, so it may be something really simple and I am just overlooking it. </p>
  
  <p>It seems to be failing on validation steps and I am getting an HTTP 400 error saying 'username must be unique', even when I am not sending a change that would be changing the current users username. Now I could probably use the view that is built into django-rest-auth to update just the user portion, then create just a custom view that only updates the profile. But that seems hacky and silly, but if it is the way to go then I will do it.</p>
  
  <p><strong>Things I have tried:</strong></p>
  
  <ul>
  <li>Tried both puts and patches. Same result.</li>
  <li>Tried overriding the put and patch methods to remove the username field from <code>request.data</code> before validation if it is the same, but that gave another error saying it is required. </li>
  <li>Tried overriding the update method in the serializer, came into a problem where I have no idea how to update a nested field. </li>
  <li>Googling to no end.</li>
  <li>Considered writing a custom validator. But I have no idea where to start on that and I wanted to make this as simple as possible and prefer built-in stuff. </li>
  </ul>
  
  <p><strong>Serializers:</strong></p>
  
  <pre><code>class UserSerializer(ModelSerializer):
  
      class Meta(UserDetailsSerializer.Meta):
          model = User
          fields = ('username', 'email', 'first_name', 'last_name')
          read_only_fields = ('email', )
  
  class UserProfileSerializer(ModelSerializer):
      user = UserSerializer(required=True, many=False)
      games = UserGameProfileSerializer(required=False, many=True)
  
      class Meta:
          model = UserProfile
          fields = ('premium', 'user', 'games')
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>class UserProfileUpdateView(generics.UpdateAPIView):
      # authentication_classes = (authentication.TokenAuthentication,)
      # permission_classes = (permissions.IsAuthenticated,)
      serializer_class = UserProfileSerializer
  
      def get_queryset(self):
          return UserProfile.objects.filter(user__username__exact=self.request.user).all()
  
      def get_object(self):
          return UserProfile.objects.filter(user__username__exact=self.request.user).get()
  </code></pre>