def update(self, request, user__username=None, *args, **kwargs): serializer = UserProfileSerializer(instance=request.user.profile, data=request.data, partial=True) if serializer.is_valid(): serializer.update() return Response({'status': 'updated profile'}) else: raise serializers.ValidationError(detail=serializer.errors)
def update_profile(self, request, user__username=None): serializer = UserProfileSerializer(instance=self.get_object(),data=request.data) if serializer.is_valid(): serializer.update() return Response({'status': 'updated profile'}) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update_profile(self, request, user__username=None): serializer = UserProfileSerializer(instance=self.get_object(), data=request.data) if serializer.is_valid(): serializer.update() return Response({'status': 'updated profile'}) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, user__username=None, *args, **kwargs): if 'user' in request.data and 'email' in request.data['user'] and \ request.user.email == request.data['user']['email']: del request.data['user']['email'] serializer = UserProfileSerializer(instance=request.user.profile, data=request.data, partial=True) if serializer.is_valid(): serializer.update() return Response({'status': 'updated profile'}) else: raise serializers.ValidationError(detail=serializer.errors)
def create(self, request, *args, **kwargs): serializer = UserProfileSerializer(data=request.data) if serializer.is_valid(): serializer.create() return Response(serializer.validated_data) return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)
def create(self, request, *args, **kwargs): serializer = UserProfileSerializer(data=request.data) if serializer.is_valid(): serializer.create() return Response(serializer.validated_data) return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)