May 2018
Beginner to intermediate
526 pages
11h 57m
English
In order to add items to the cart, we need a form that allows the user to select a quantity. Create a forms.py file inside the cart application directory and add the following code to it:
from django import formsPRODUCT_QUANTITY_CHOICES = [(i, str(i)) for i in range(1, 21)]class CartAddProductForm(forms.Form): quantity = forms.TypedChoiceField( choices=PRODUCT_QUANTITY_CHOICES, coerce=int) update = forms.BooleanField(required=False, initial=False, widget=forms.HiddenInput)
We will use this form to add products to the cart. Our CartAddProductForm class contains the following two fields:
Read now
Unlock full access