Make SimpleBasketForm a bit easier to redefine when BasketForm has been overridden
@@ -299,17 +299,22 @@ class AddToBasketForm(forms.Form):
return options
-class SimpleAddToBasketForm(AddToBasketForm):
- """
- Simplified version of the add to basket form where the quantity is
- defaulted to 1 and rendered in a hidden widget
-
- Most of the time, you won't need to override this class. Just change
- AddToBasketForm to change behaviour in both forms at once.
- """
-
+class SimpleAddToBasketMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if 'quantity' in self.fields:
self.fields['quantity'].initial = 1
self.fields['quantity'].widget = forms.HiddenInput()
+
+
+class SimpleAddToBasketForm(SimpleAddToBasketMixin, AddToBasketForm):
+ """
+ Simplified version of the add to basket form where the quantity is
+ defaulted to 1 and rendered in a hidden widget
+
+ If you changed `AddToBasketForm`, you'll need to override this class
+ as well by doing:
+
+ class SimpleAddToBasketForm(SimpleAddToBasketMixin, AddToBasketForm):
+ pass
+ """
