I have a form like so:
class PartnerProductsForm(forms.Form):
product = forms.ModelChoiceField(
queryset=Product.objects.all(),
widget=forms.CheckboxSelectMultiple(
attrs={"checked": ""}
),
empty_label=None,
)
And my views:
...
product_form = PartnerProductsForm(request.POST or None)
if product_form.is_valid():
# do stuff
But when I submit I get the following error:
TypeError: int() argument must be a string or a number, not 'list'
It seems like the form validation is expecting an int, but of course I will be retuning a list of the checked options. How am I supposed to deal with this?
The form field you're looking for is ModelMultipleChoiceField, rather than ModelChoiceField.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With