1👍
✅
Your PAYMENT_OPTIONS
choice array is OK.
This is how I have it getting the payment options directly from the Model
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['payments'] = forms.ModelMultipleChoiceField(
queryset=Payment.objects.all(),
required=True,
error_messages = {'required': 'Payment Options is Required!'},
label='Payment Types',
widget=forms.CheckboxSelectMultiple(attrs={
'class': 'checkbox-inline',}))
Please note the ModelForm
class MyForm(forms.ModelForm):
and also the ModelMultipleChoiceField
self.fields['payments'] = forms.ModelMultipleChoiceField(
please also note that I’m using POST
method to save the results.
Source:stackexchange.com