Re: Can't get initial value into form correctly.

2016-05-15 Thread Chris Kavanagh
Stephen, my apologies, it most certainly did work! You did make one small mistake by forgetting the quotes around the item and the form in the dict. . . like this [{'item': item, 'form': form}]. This is why it didn't work the 1st time I tried it, you were missing the quotes and I didn't catch it

Re: Can't get initial value into form correctly.

2016-05-15 Thread Chris Kavanagh
Nope, can't get this to work either. This way, nothing works. Nothing will display on the page this way, not the products nor the form. I see now what you were trying to do in the 1st example, however as you said, django templates won't allow that. I was able to do the form in the template

Re: Can't get initial value into form correctly.

2016-05-14 Thread Stephen J. Butler
It's now a dict, so you have to index into it. The for loop won't magically know which element of add_product_forms you want. You'd want add_product_forms[item.pk]. But ugg... apparently Django templates won't (out of the box) let you index a dict using another variable. Thanks for reminding me

Re: Can't get initial value into form correctly.

2016-05-14 Thread Chris Kavanagh
Yeah, I'm obviously doing something wrong in the template, Stephen. I'm not quite sure what I'm supposed to do (in the template). You kinda lost me on the last sentence, "Then adjust your template to index into add_product_forms based on item.pk." Could you give me a hint, please? And thank you

Re: Can't get initial value into form correctly.

2016-05-14 Thread Chris Kavanagh
Thank for the answer, Stephen. However, I'm still a little confused, and it apparently doesn't' work unless I'm doing something wrong in the template. In the template, I'm supposed to change the "add_product_form" to "add_product_forms" in the template? In other words, "add_product_forms.quantity"

Re: Can't get initial value into form correctly.

2016-05-14 Thread Stephen J. Butler
You assign to context every loop iteration. So at the end, only the last add_product_form constructed is ever used. Try this: def show_cart(request): cart_id = _cart_id(request) cart_items = CartItem.objects.filter(cart_id=cart_id) add_product_forms = {} for item in cart_items:

Can't get initial value into form correctly.

2016-05-14 Thread Chris Kavanagh
I'm working on an online shop, and I'm having a problem in the cart, here's a screen shot (http://pasteboard.co/Vwnv2T0.png). I'd like the form for each item (product) to show it's current quantity (that's already been added to the cart) as an initial value as most ecommerce sites do. I've