def post(self, request): ps = UserSerializer(data=request.data) if ps.is_valid(): ps.save() message = {"message": "user Saved"} else: message = {"error": ps.errors} return Response(message)
def update_user(request, id=None): queryset = User.objects.get(id=id) serializer = UserSerializer(queryset, data=request.data) if serializer.is_valid(): serializer.save() return Response({"Status": "Updated"}, status=status.HTTP_205_RESET_CONTENT) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, user_id): try: res = User.objects.get(no=user_id) d1 = request.data ps = UserSerializer(res, d1, partial=True) if ps.is_valid(): ps.save() message = {"message": "user Updated"} else: message = {"error": ps.errors} return Response(message) except User.DoesNotExist: message = {"error": "user id is Invalid"} return Response(message)
def my_jwt_response_handler(token, user=None, request=None): return { 'token': token, 'user': UserSerializer(user, context={ 'request': request }).data }
def get(self, request, user_id): try: res = User.objects.get(no=user_id) return Response(UserSerializer(res).data) except User.DoesNotExist: message = {"error": "User id is Invalid"} return Response(message)
def get(self, request): qs = User.objects.all() ps = UserSerializer(qs, many=True) return Response(ps.data)
def get_user(request): queryset = User.objects.all() serializer = UserSerializer(queryset) return Response(serializer.data)