from datetime import timedelta
from .models import Table, Booking

def book_restaurant_table(restaurant, people, booking_date_time):
    pass

def get_first_table_available(restaurant, booking_date_time, people):
    delta = timedelta(seconds=60*90)  # 1,5 hours time delta
    l_bound_time = booking_date_time - delta
    u_bound_time = booking_date_time + delta

    tables_booked = Booking.objects.filter(table__restaurant=restaurant,
        booking_date_time__gt=l_bound_time, booking_date_time__lt=u_bound_time).values('table')
    tables_booked_ids = [x['table'] for x in tables_booked]

    tables = Table.objects.filter(restaurant=restaurant,
        restaurant__opening_time__lte=booking_date_time.hour,
        restaurant__closing_time__gte=booking_date_time.hour+1.5,
        size__gte=people).exclude(id__in=tables_booked_ids).order_by('size')

    if tables.count() == 0:
        return None
    else:
        return tables[0]

@@ -203,16 +203,33 @@
 , people
+, minutes_slot=90
 ):%0A    d
@@ -260,35 +260,21 @@
 =60*
-90)  # 1,5 hours time delta
+minutes_slot)
 %0A   
@@ -775,11 +775,34 @@
 our+
-1.5
+(minutes_slot / float(60))
 ,%0A  

Allow booking a specific amount of time