Exemple #1
0
 def post(self, request, format=None):
     serializer = AccountsSerializer(data=request.data,
                                     context={'request': request})
     if (serializer.is_valid()):
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
 def put(self, request, pk, format=None):
     user = self.get_user(pk)
     serializer = AccountsSerializer(user,
                                     data=request.data,
                                     context={'request':
                                              request})  # level 2
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)