When trying to update a user the following message appears: "A user with this username already exists"
I have a standard Django User model and I have another profile template that extends.
How do I update this data, including the user profile.
Thank you.
Model
class Profile(User):
nome_empresa = models.CharField(max_length=200)
cnpj = models.CharField(max_length=15)
def __str__(self):
return self.nome_empresa
Serializer
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')
View
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)