Hello Everyone,
I hope someone can help me out so i can continue my learning. I took a udemy course and now i want to take the project futher.
I created a ModelForm that has options for size and style. I can get the form to display on the page. I cannot figure out how to get the size and styles added to the cart. I have tried several different ways and no go.
code before trying the get Model Form data.
def add_cart(request, item_id):
item = Item.objects.get(id=item_id)
try:
cart = Cart.objects.get(cart_id=_cart_id(request))
except Cart.DoesNotExist:
cart = Cart.objects.create(
cart_id=_cart_id(request)
)
cart.save()
try:
cart_item = CartItem.objects.get(
item=item, cart=cart
)
if cart_item.quantity < cart_item.item.stock:
cart_item.quantity += 1
cart_item.save()
except CartItem.DoesNotExist:
cart_item = CartItem.objects.create(
item=item,
quantity=1,
cart=cart
)
cart_item.save()
return redirect('cart_detail')
thanks for the help