В Django customize form форма не отправляла данные на заднюю сторону
Я пытаюсь настроить ModelMultipleChoiceField в форме, но когда я пытаюсь отправить форму, я получаю ошибку Enter a list of values
my form.py
class AppointmentCreateViewForm(forms.ModelForm):
patient= forms.ModelChoiceField( queryset=Patient.objects.all(),label="Patient")
appointmentDate = forms.DateField(label="Appointment date", widget=forms.DateInput(format='%Y-%m-%d'))
appointmentType = forms.ChoiceField(choices=AppointmentTypes, required=False, label="Appointmen type")
appointmentStatus = forms.ChoiceField(label="Appointment Status", choices=AppointmentStatuss)
operation = forms.ModelMultipleChoiceField(widget=forms.Select(attrs={
'class': 'js-example-basic-multiple',
'name': 'states[]',
'multiple': 'multiple'
}), queryset=Operation.objects.all(),label="Operation")
class Meta:
model = Appointment
fields = ('patient', 'appointmentDate', 'appointmentType','appointmentStatus','operation')
мой html
<section>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save" />
</form>
</section>
my operation model.py
class Operation(models.Model):
operationName = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.operationName
def get_absolute_url(self):
return reverse('operations')