Customize Create funciton in DRF viewset

121 Views Asked by At

I want to customize the user viewset i.e. when the user registers the user account was created as well.

im doing this :

class CustomUserCreate(APIView):
    permission_classes = [AllowAny]
    def post(self, request):
        serializer = RegisterUserSerializer(data=request.data)
        if serializer.is_valid():
            user = serializer.save()
            if user:
                profile_serializer = ProfileShortSerializer(data = request.data)
                profile = profile_serializer.save()
                return Response(status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)```

is this the right approch?

0

There are 0 best solutions below