From a301aa78b7763c9c9a8adec29a2d678f49f158ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 10 Jun 2023 23:28:56 -0400 Subject: [PATCH] fix rating count --- catalog/templates/item_base.html | 2 +- journal/models.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/catalog/templates/item_base.html b/catalog/templates/item_base.html index 725b63e5..58429e55 100644 --- a/catalog/templates/item_base.html +++ b/catalog/templates/item_base.html @@ -286,7 +286,7 @@

{{ item.rating | floatformat:1 }} / 10

-

{{ item.rating_count }}人评分

+

{{ item.rating_count }}个评分

diff --git a/journal/models.py b/journal/models.py index 79051473..15c26701 100644 --- a/journal/models.py +++ b/journal/models.py @@ -341,7 +341,8 @@ class Rating(Content): @staticmethod def get_rating_count_for_item(item): - stat = Rating.objects.filter(item=item, grade__isnull=False).aggregate( + ids = item.child_item_ids + [item.id] + stat = Rating.objects.filter(item_id__in=ids, grade__isnull=False).aggregate( count=Count("item") ) return stat["count"]