Display labels of ModelMultipleChoiceField

Viewed 14

How to display the labels of the choices in a ModelMultipleChoiceField ?

This is the form :

class MakeAnAppointmentForm(forms.Form):
    time_slot = forms.ModelMultipleChoiceField(queryset = None, widget=forms.CheckboxSelectMultiple())

    def __init__(self,*args,**kwargs):
        date = kwargs.pop('date')
        super().__init__(*args,**kwargs)
        self.fields['time_slot'].queryset = Appointment.objects.filter(date = date).values_list('time_slot', flat = True)
        self.fields['time_slot'].label = "date"

But it displays this :

enter image description here

And I want this :

enter image description here

in accordance to this :

TIMESLOT_CHOICES = (('0', '09:00 - 09:30'),
        ('1', '09:30 - 10:00'),
        ('2', '10:00 - 10:30'),
        ('3', '10:30 – 11:00')...

How is this possible ? Thank you.

0 Answers
Related