How can I make a dictionary efficiently from a queryset.
I have days and each day has times associated with it like
Day1 - Time1
Day1 - Time2
Day1 - Time3
Day2 - Time1
I would like to make a list
of dictionary
like [{"day":'Day1', "time":'Time1, Time2, Time3'}, ...]
This join
listof = ",".join(str([ab.day.day, str(ab.time)]) for ab in vqs.clinicDoctor_dayShift.all().order_by('day__id'))
gives me string like
['Sunday', '15:01:00'],['Sunday', '16:02:00'],['Monday', '09:01:00'],['Monday', '15:01:00'],['Monday', '16:02:00'],['Tuesday', '09:01:00'],['Tuesday', '16:02:00']
I would like to have a list
like this
[{'day':'Sunday', 'time':'15:01:00, 16:02:00, 09:01:00'},{'day':'Monday', 'time':'15:01:00, 16:02:00'},{'day':'Tuesday', 'time':'09:01:00, 16:02:00'}]
Can anyone please help me with this.
Thank you.