I have a small SHOP with up to 20 products.
Currently I have hardcoded the maximum quantity
per item in form CartAddProductForm
- for each item allowed quantity choice is up to 10 - see the code below:
PRODUCT_QUANTITY_CHOICES = [(i, str(i)) for i in range(1, 11)]
class CartAddProductForm(forms.Form):
quantity = forms.TypedChoiceField(
choices=PRODUCT_QUANTITY_CHOICES,
coerce=int,
label = '',
widget=forms.Select(attrs={'class': 'quantity'}),
)
override = forms.BooleanField(required=False,
initial=False,
widget=forms.HiddenInput)
Additionally I defined max_quantity
attribute in the Product
model.
How should I define my form
to allow different choices per product ?
Thanks.