search response includes min and max prices

This commit is contained in:
Sam
2021-02-26 10:58:36 +00:00
parent 9b02c05f4e
commit 86020afd27
3 changed files with 40 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import logging
from django.db.models import Q
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector, TrigramSimilarity
from django.db.models import Max, Min
from products.models import Product
@@ -189,7 +190,12 @@ def find_related_products_v6(keyword, shipping_cost=None, discount=None, categor
if price_max is not None:
products_qs = products_qs.filter(price__lt=price_max)
return set(products_qs)
# get min_price and max_price
min_price = products_qs.aggregate(Min('price'))
max_price = products_qs.aggregate(Max('price'))
return set(products_qs), min_price, max_price
def find_related_products_v4(keyword):