How to disable the options in select with Django
I created a calendar with dates where appointments can be made.
I then created a form to select appointments.
I want each time an appointment is made, it to be grayed out for the exact day and time it was made.
For March 2, 2025 I booked an appointment at 9am, for January 24, I booked an appointment at 8am and for March 6, 2025, I booked an appointment at 2:15pm.
However, as you can see in the picture, when I click on March 2, 2025, the times 8am, 9am and 2:15pm are all grayed out even though I used them for different days.
Thanks in advance
#**********************************
def formatday(self, day, rdvs):
select_hour = RdvForm()
select_dat = Rdv.objects.all().values()
p = len(select_dat)`enter code here`
rr =len(select_hour['start_time'])
ls_h = []
ls_d =[]
ls_dd=[]
# add value in list
for i in range(p):
ls_h.append(select_dat[i]["start_time"])
for lis_d in range(p):
f = str(select_dat[lis_d]["select_date"])
ls_d.append(f[:7])
#list day year
for dd in range(p):
ff = str(select_dat[dd]["select_date"])
ls_dd.append(int(ff[8:]))
year_month_curent =str (self.year)+'-'+str("{:02}".format(self.month))
htm = f'<select name="start_time" id="id_start_time">'
for i in range(rr):
if select_hour['start_time'][i].data['value'] in ls_h and year_month_curent in ls_d and day in ls_dd:
htm+= f'<option class="{i}" disabled="disabled" value="{select_hour['start_time'][i].data["value"]}">{select_hour['start_time'][i].data["value"]}</option>'
else:
htm+= f'<option value="{select_hour['start_time'][i].data["value"]}">{select_hour['start_time'][i].data["value"]}</option>'
htm+=f'</select>'
#*****************
for i in range(rr):
if day != 0:
return f"<td><span class='date' style='font-weight:bold'
{'{:02}'.format(day)}</span><br> {htm} </td>"
return '<td></td>'