I've done some more testing with these two functions. It seems that when the function 'deletecart' is accessed the line 'del request.seesion['cart'][0]' is working. It's deleting the first element in request.session['cart']. Because I get directly returned to my showcart function and the first element is gone. However, it's gone only temporarily. When I try to delete the first element again nothing happens. For some reason the first element that I deleted first is somehow still there behind the scenes. When I go to a new page and then back to showcart the first element that i thought I deleted is still there.
Here are my views def showcart(request, style_id, choice_id): s = Style.objects.get(id=style_id) c = Choice.objects.get(id=choice_id) cart = request.session.get('cart', []) cart.append({'style': s, 'choice': c}) request.session['cart'] = cart pr = 0 for a in cart: pr = pr + a['choice'].price.name return render_to_response('show_test.html', {'mychoice': cart, 'p': pr}) def deletecart(request): del request.session['cart'][0] pr = 1000 return render_to_response('show_test.html', {'mychoice': request.session['cart'], 'p': pr}) //////////////////////// If I move the line 'del request.session['cart'][0] up into my showcart function right after 'request.session['cart'] = cart' then it works fine. However, I don't want to add a product to the cart and then delete the first item in the cart. It's just weird how that line 'del request.session['cart'][0]' works fine in the showcart function but doesn't work right in the deletecart function. Thanks for any help. On Jul 20, 11:25 pm, Greg <[EMAIL PROTECTED]> wrote: > Hello, > I have the following views > > def showcart(request, style_id, choice_id): > s = Style.objects.get(id=style_id) > #assert False,s > c = Choice.objects.get(id=choice_id) > #x = c.size, " ", c.price > cart = request.session.get('cart', []) > cart.append({'style': s, 'choice': c}) > request.session['cart'] = cart > pr = 0 > for a in cart: > pr = pr + a['choice'].price.name > return render_to_response('show_test.html', {'mychoice': cart, 'p': > pr}) > > def deletecart(request): > del request.session['cart'][0] > # x = request.session['cart'][0] > # assert False,x > return render_to_response('themainpage.html', {}) > > //////////////////// > > Shouldn't the line in the 'deletecart' view delete the first item in > my dictionary? Whenever I access the 'deletecart' view I don't get an > error, but it doesn't delete the dictionary[0] element. > > Whenever I do a 'assert False, x' I get the following error: > > {'style': <Style: 439r>, 'choice': <Choice: (<Size: 2'3 x 4'5>, > <Price: 69>)>} > > so why isn't the above line getting deleted from my dictionary when > using 'del request.session['cart'][0]'? > > Thanks for any help --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---