0

我想自定义用户视图集,即用户注册时也创建了用户帐户。

我这样做:

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?

4

0 回答 0