From 2c28b87f1e7aec2e120a93e024c284f4cff0344b Mon Sep 17 00:00:00 2001 From: async-upgrade Date: Sun, 6 Sep 2026 14:45:16 +0800 Subject: [PATCH] fix: final serializer.data -> adata migration (chat/blacklist/article), blacklist select_related --- article/views.py | 2 +- chat/views.py | 8 ++++---- user/views/blacklist.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/article/views.py b/article/views.py index 977e81f..b7a28fb 100644 --- a/article/views.py +++ b/article/views.py @@ -324,7 +324,7 @@ class ArticleCommentListCreateView(generics.ListCreateAPIView): with transaction.atomic(): comment = serializer.save(user=request.user, article=article) comment_id = comment.id - comment_content = serializer.data.get('content', '') + comment_content = serializer.validated_data.get('content', '') article_title = article.title article_author_id = article.author_id parent_comment_id = comment.parent_id diff --git a/chat/views.py b/chat/views.py index 964b9b3..c953971 100644 --- a/chat/views.py +++ b/chat/views.py @@ -49,7 +49,7 @@ class FriendRequestListView(APIView): queryset = queryset.select_related('from_user', 'to_user') requests_list = [r async for r in queryset] serializer = FriendRequestSerializer(requests_list, many=True, context={'request': request}) - return create_standardized_response(data=serializer.data, code=ResponseCode.SUCCESS) + return create_standardized_response(data=await serializer.adata, code=ResponseCode.SUCCESS) @swagger_auto_schema( tags=['AI对话'], @@ -90,7 +90,7 @@ class FriendRequestListView(APIView): friend_request = await FriendRequest.objects.acreate(from_user=request.user, to_user=to_user, message=message) serializer = FriendRequestSerializer(friend_request, context={'request': request}) - return create_standardized_response(data=serializer.data, code=ResponseCode.SUCCESS, status_code=status.HTTP_201_CREATED) + return create_standardized_response(data=await serializer.adata, code=ResponseCode.SUCCESS, status_code=status.HTTP_201_CREATED) class FriendRequestAcceptView(APIView): @@ -179,7 +179,7 @@ class FriendListView(APIView): ).select_related('user1', 'user2') friendships_list = [f async for f in friendships] serializer = FriendshipSerializer(friendships_list, many=True, context={'request': request}) - return create_standardized_response(data=serializer.data, code=ResponseCode.SUCCESS) + return create_standardized_response(data=await serializer.adata, code=ResponseCode.SUCCESS) @swagger_auto_schema( tags=['AI对话'], @@ -430,7 +430,7 @@ class ConversationMessageView(APIView): ) serializer = ChatMessageSerializer(message, context={'request': request}) - return create_standardized_response(data=serializer.data, code=ResponseCode.SUCCESS, status_code=status.HTTP_201_CREATED) + return create_standardized_response(data=await serializer.adata, code=ResponseCode.SUCCESS, status_code=status.HTTP_201_CREATED) class ConversationClearView(APIView): diff --git a/user/views/blacklist.py b/user/views/blacklist.py index c745a6a..5bb1d2f 100644 --- a/user/views/blacklist.py +++ b/user/views/blacklist.py @@ -28,7 +28,7 @@ class BlacklistListAPIView(APIView): responses={200: success_response, 401: unauthorized_response}, ) async def get(self, request): - queryset = Blacklist.objects.filter(user=request.user) + queryset = Blacklist.objects.filter(user=request.user).select_related('blocked_user') search = request.query_params.get('search', '') if search: @@ -49,7 +49,7 @@ class BlacklistListAPIView(APIView): return create_standardized_response( data={ - 'results': serializer.data, + 'results': await serializer.adata, 'total': total, 'page': page, 'page_size': page_size,