def post(self, request, format=None):
        serializer = ProfileSerializer(data=request.data)

        if serializer.is_valid():
            serializer.create(validated_data=request.data)
            return Response(serializer.data, status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    def put(self, request, pk, format=None):
        profile = self.get_object(pk)
        serializer = ProfileSerializer(profile, data=request.data)

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 3
0
 def post(self, request, *args, **kwargs):
     serializer = ProfileSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         profile = serializer.save()
         token, created = Token.objects.get_or_create(user=profile.user)
         return Response({'profile': serializer.data, 'token': token.key})
     else:
         return Response(
             serializer.errors, 
             status=status.HTTP_400_BAD_REQUEST
         )