From 255019de7ade9e9caafa3b81a1840486eb1471a0 Mon Sep 17 00:00:00 2001 From: yuetsh <51725939@qq.com> Date: Mon, 1 Jul 2024 00:14:20 +0800 Subject: [PATCH] add count --- comment/views/oj.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/comment/views/oj.py b/comment/views/oj.py index c272320..12a6bbc 100644 --- a/comment/views/oj.py +++ b/comment/views/oj.py @@ -1,4 +1,4 @@ -from django.db.models import Avg +from django.db.models import Avg, Count from django.db.models.functions import Round from comment.models import Comment from problem.models import Problem @@ -59,10 +59,15 @@ class CommentAPI(APIView): ) if comments.count() == 0: return self.success() + count = comments.count() rating = comments.aggregate( description=Round(Avg("description_rating"), 2), difficulty=Round(Avg("difficulty_rating"), 2), comprehensive=Round(Avg("comprehensive_rating"), 2), ) contents = comments.exclude(content="").values_list("content", flat=True) - return self.success({"rating": rating, "contents": list(contents)}) + return self.success({ + "count": count, + "rating": rating, + "contents": list(contents), + })