foad-heidari / dj-booking

free and complete booking package for Django
Other
61 stars 28 forks source link

Solution for Max Booking for Time #41

Closed gabekerchner closed 1 year ago

gabekerchner commented 2 years ago

I found a solution for this item, could be implement in the future:

In views.py modify the function get_available_time() adding like this:

  1. Add this line in definition: max_booking_per_time = booking_settings.max_booking_per_time

  2. Set While like this:

    while True:
    is_taken = False # Add this line
    if (existing_bookings.count() == max_booking_per_time): # Add this if
        is_taken = any([x[0] == next_time for x in existing_bookings])
    time_list.append(
        {"time": ":".join(str(next_time).split(":")[:-1]), "is_taken": is_taken})
    next_time = add_delta(next_time, datetime.timedelta(
        minutes=int(booking_settings.period_of_each_booking)))
    if next_time > booking_settings.end_time:
        break

Enjoy 😄

foad-heidari commented 2 years ago

@gabekerchner thanks for your comment. if you create a PR it will be great!

foad-heidari commented 1 year ago

okay i want to add this future

it should be like this :

is_taken = False
for x in existing_bookings:
    if x == next_time and existing_bookings.count(x) >= booking_settings.max_booking_per_time:
        is_taken = True