예제 #1
0
 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)
예제 #2
0
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)
예제 #3
0
 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)
예제 #4
0
def my_jwt_response_handler(token, user=None, request=None):
    return {
        'token': token,
        'user': UserSerializer(user, context={
            'request': request
        }).data
    }
예제 #5
0
 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)
예제 #6
0
 def get(self, request):
     qs = User.objects.all()
     ps = UserSerializer(qs, many=True)
     return Response(ps.data)
예제 #7
0
def get_user(request):
    queryset = User.objects.all()
    serializer = UserSerializer(queryset)
    return Response(serializer.data)