[Solved]-How to design shopping basket using session?

15👍

I wouldn’t use a model. You can store the values directly in the session. Considering that you can store everything in the session you can store the items in a dictionary do something like.

def view_cart(request):
    cart = request.session.get('cart', {})
    # rest of the view

def add_to_cart(request, item_id, quantity):
    cart = request.session.get('cart', {})
    cart[item_id] = quantity
    request.session['cart'] = cart
    # rest of the view
👤JoseP

Leave a comment