Skip to content

Commit

Permalink
Fix bug with best/worst rated items - shop
Browse files Browse the repository at this point in the history
  • Loading branch information
tomik-z-cech committed Mar 8, 2024
1 parent 35a4884 commit e6ff664
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion items/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.paginator import Paginator
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Count, F, ExpressionWrapper, fields
from items.models import Category, Item, ItemComments
from items.forms import ItemCommentForm

Expand All @@ -26,7 +27,13 @@ def get(self, request, category_pk, *args, **kwargs):
queryset = Item.objects.all().order_by('item_name').annotate(
item_comments_num=Count(
"item_comments", filter=Q(item_comments__approved=1)
)
)).annotate(
like=Count("item_likes"),
dislike=Count("item_dislikes"),
item_likes_num=ExpressionWrapper(
F('like') - F('dislike'),
output_field=fields.IntegerField()
)
)
selected_category = 'All Products'
else:
Expand Down

0 comments on commit e6ff664

Please sign in to comment.