PacktPublishing/Django-2-by-Example

Chapter 09

osmminog opened this issue · 2 comments

The product recommendation system gives an error. "zincrby() got multiple values for argument 'amount'"
def products_bought(self, products): product_ids = [p.id for p in products] for product_id in product_ids: for with_id in product_ids: # get the other products bought with each product if product_id != with_id: # increment score for product purchased together r.zincrby(self.get_product_key(product_id), with_id, amount=1)

Python 3.7.9, Django 3, Redis server v=3.0.6

Tell me what could be the problem?

Chapter 9 throws an error if all the products from the cart are removed.
The following should be added to recommender.py

def suggest_products_for(self, products, max_results=6):
product_ids = [p.id for p in products]
# Add this to solve the bug
if len(products) == 0:
return []

Chapter 9 Suggestion:
products_bought method from recommender.py is nowhere being called.

Suggestion to add in tasks.py the following code:
order = Order.objects.get(id=order_id)
**order_items = order.items.all()
products = []

for oi in order_items:
    products.append(oi.product)

recommender = Recommender()
recommender.products_bought(products)**