[Django]-Django rest framework RetrieveUpdateAPIView

5👍

Try editing your view like this,

class UserUpdateAPIView(generics.RetrieveUpdateAPIView):
    permission_classes = (permissions.IsAdminUser,)
    serializer_class = UserUpdateSerialier
    lookup_field = 'username'

    def get_object(self):
        username = self.kwargs["username"]
        return get_object_or_404(User, username=username)

    def put(self, request, *args, **kwargs):
        return self.update(request, *args, **kwargs)

2👍

You need to set lookup_field = 'username' to the UserUpdateAPIView just like you did with the UserDetailAPIView

Leave a comment