We now have the models in place. Let's add a new form that will display the cart data on a page for editing. Open the forms.py file at gamestore/main/, and at the end of the file add the following code:
ShoppingCartFormSet = inlineformset_factory( ShoppingCart, ShoppingCartItem, fields=('quantity', 'price_per_unit'), extra=0, widgets={ 'quantity': forms.TextInput({ 'class': 'form-control quantity', }), 'price_per_unit': forms.HiddenInput() } )
Here, we create an inline formset using the function inlineformset_factory. Inline formsets are suitable when we want to work with related objects via a foreign key. This is very convenient in the case we have here; we have a model ShoppingCart that relates to the