title: How to update user data using django and rest framework?
body: <p>When trying to update a user the following message appears: "A user with this username already exists"</p>
  
  <p>I have a standard Django User model and I have another profile template that extends.</p>
  
  <p>How do I update this data, including the user profile.</p>
  
  <p>Thank you.</p>
  
  <p>Model</p>
  
  <pre><code>class Profile(User):
      nome_empresa = models.CharField(max_length=200)
      cnpj = models.CharField(max_length=15)
  
      def __str__(self):
          return self.nome_empresa
  </code></pre>
  
  <p>Serializer</p>
  
  <pre><code>class ProfileSerializer(serializers.ModelSerializer):
      class Meta:
          model = Profile
          fields = ('nome_empresa', 'cnpj')
  
  
  class UserSerializer(serializers.ModelSerializer):
      profile = ProfileSerializer()
      class Meta:
          model = User
          fields = ('username', 'email', 'first_name', 'last_name', 'profile')
  </code></pre>
  
  <p>View</p>
  
  <pre><code>class usuario(APIView):
  
  
      def patch(self, request, format=None):
  
          user = UserSerializer(data=request.data)
  
          if user.is_valid():
              user.update(instance=request.user)
              return Response(HTTP_200_OK)
  
          return Response(user.errors)
  </code></pre>