Hello, I want to develop a basic quantity widget that is a dropdown selection box, consuming an integer which will be the maximum amount of quantity, users can select from 1 to the maximum quantity.
And in the end my form will be using this widget and if somehow the given amount is greater than the maximum, it shouldn't validate. (indeed regular users won't be able to select more than maximum but I guess it can be tried by sending direct request to the server.)
How can this be done?
Thanks
edit: I think it can be something like this to begin with, however I want my field to be a select(from 1 to max maximum quantity), not textinput field.
def quantity_field(quantity=1):
class QuantityForm(forms.Form):
forms.IntegerField(label="Purchase quantity",min_value=1,max_value=quantity,required=True,widget=forms.Select)
return QuantityForm