changes to related product action, test ok
This commit is contained in:
@@ -85,14 +85,42 @@ def extract_search_filters(result_set):
|
||||
return filter_dict
|
||||
|
||||
|
||||
def get_related_products(description, tags, attributes, category):
|
||||
products_qs = Product.objects.filter(
|
||||
Q(description=description) |
|
||||
Q(tags__in=tags) |
|
||||
Q(attributes__in=attributes) |
|
||||
Q(category=category)
|
||||
)[:10]
|
||||
return products_qs
|
||||
def get_related_products(product):
|
||||
"""Make different db searches until you get 10 instances to return
|
||||
"""
|
||||
total_results = []
|
||||
|
||||
# search by category
|
||||
category_qs = Product.objects.filter(category=product.category)[:10]
|
||||
# add to results
|
||||
for item in category_qs:
|
||||
total_results.append(item)
|
||||
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by tags
|
||||
tags_qs = Product.objects.filter(tags__in=product.tags.all())[:10]
|
||||
# add to results
|
||||
for item in tags_qs:
|
||||
total_results.append(item)
|
||||
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by coop
|
||||
coop_qs = Product.objects.filter(company=product.company)[:10]
|
||||
# add to results
|
||||
for item in coop_qs:
|
||||
total_results.append(item)
|
||||
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by latest
|
||||
latest_qs = Product.objects.order_by('-created')[:10]
|
||||
# add to results
|
||||
for item in coop_qs:
|
||||
total_results.append(item)
|
||||
|
||||
return total_results[:10]
|
||||
|
||||
|
||||
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
|
||||
Reference in New Issue
Block a user