How to get list of time slots in database

Submitted 4 years, 6 months ago
Ticket #232
Views 706
Language/Framework Django
Priority Medium
Status Closed

Hello everyone hope you all doing well.

I need little guidance/help

I want to get all slots between the start time and end time in slots.Each slot will be of 15 minutes.How can we send all slots to the database

class Schedule(models.Model):

doctor=models.ForeignKey(Doctor, on_delete=models.CASCADE)

DAYS=(('Mon','Monday'),

('Tue','Tuesday'),

('Wed','Wednesday'),

('Thu','Thursday'),

('Fri','Friday'),

('Sat','Saturday'),

('Sun','Sunday'),

)

days=models.CharField(choices=DAYS,max_length=20,null=True,blank=True)

start_time=models.TimeField()

end_time=models.TimeField()

slot_time=models.CharField(max_length=50,default='15')

slots=models.CharField(max_length=5000,blank=True,null=True)

def __str__(self):

return str(self.doctor)

Submitted on Oct 15, 20

Do you want to store every 15 mins slots between start & end time? - Vengat 4 years, 6 months ago

yes buddy,for e.g [(10:00,10:15),(10:00,10:30),,,,,,((17:45,18:00))] like this buddy,so that when the patient will click on time slots he will get the list of slots,and he can book slot according to him - ashutoshmishra333 4 years, 6 months ago

Follow up on Ticket status. If everything looks good then please close the ticket. - Vengat 4 years, 6 months ago
add a comment

1 Answer

Verified

Found this stuff somewhere in forum, but i think this should help you.

You can create a generator something like to pass the start and end time and get the time slot and store it in DB

import datetime

def time_slots(start_time, end_time):
    t = start_time
    while t <= end_time:
        yield t.strftime('%H:%M')
        t = (datetime.datetime.combine(datetime.date.today(), t) +
             datetime.timedelta(minutes=15)).time()

And if you pass the start and end time like below,

>>> import datetime
>>> start_time = datetime.time(10, 00)
>>> end_time = datetime.time(11, 00)
>>> list(time_slots(start_time, end_time))
['10:00', '10:15', '10:30', '10:45', '11:00']
>>> 

After you get the time slot from the above generator , you can store the same in timeslot field in your model.

Submitted 4 years, 6 months ago

@Ashutosh, Can you confirm whether this helps you?.

- Vengat 4 years, 6 months ago

Thanks buddy,but I have done this,I want to send this to the database through postman,

- ashutoshmishra333 4 years, 6 months ago

@Ashutosh, I would suggest to raise new ticket for any new requirement questions. So that it would be easy for developers to help you at the earliest. If the current ticket issue resolved then kindly close the ticket.

- Vengat 4 years, 6 months ago

It has not resolved buddy,,

- ashutoshmishra333 4 years, 6 months ago

I have pretty much shared the steps to use to insert into database. When you say its not working then share me your code you have developed( may be share your github or update your code in ticket). And also lets focus to do the insert using Django shell then may be we can work on Postman.

- sunil 4 years, 6 months ago

As we are not getting any update on this ticket for a while, We are closing this ticket.

- Vengat 4 years, 5 months ago


Latest Blogs