Reputation: 2003
I have created a simple API for editing user profile.
class EditProfile(generics.UpdateAPIView):
serializer_class = UserSerializer
queryset = get_user_model().objects.all()
permission_classes = (IsAuthenticated,)
How can I prevent the user from editing other user's profile?
Upvotes: 0
Views: 116
Reputation: 599778
You should simply define get_object
so that it always returns the current user.
def get_object(self):
return self.request.user
Note there's now no need to specify a slug parameter in the URL.
Upvotes: 1