On Friday 17 February 2017 01:43:12 MikeKJ wrote:

> As an adder:
> 
> 
> Each resource has a finite number so is  there a way to utilise the
> max number of resources within a resource so that we know how many
> resources are unused?

Hmm, I'd rethink my datamodel. Everything is far easier to handle if a resource 
is a 
unique thing that can't be booked by two users at the same time.

This also affects sorting. It is easy if there's only one overlap, but things 
get tricky, 
when there's more than one, cause you'd have to wait for the booking to show up 
that 
isn't overlapping.

It's also not very clear what you're trying to show by sorting it that way and 
that is 
probably easier to do with a better data model.

Let's say you have 10 bedrooms. Users book a "bedroom" and you allocate one 
from 
the available bedrooms for that timeslot. If none are available, you deny 
booking. For 
each hour of the day, it is trivial to calculate the number of rooms unused.
You filter out target date, break down start + hours in start times for each 
hour, build 
two sets for target slot and room slot and see if they intersect:

Room 1 for today:
start: 9
hours: 4
becomes
set(9, 10, 11, 12)

Room 2 for today:
start 11:
hours: 2
becomes:
set(11, 12)

Room 3 for today:
start: 12
hours: 4
becomes
set(12, 13, 14, 15)

Target:
start: 11
becomes
set(11)

Room 1 and 2 intersect with target. Room 3 is needed at 12 because both 1 & 2 
are 
still occupied.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2939382.eWNLQdzvJ7%40devstation.
For more options, visit https://groups.google.com/d/optout.

Reply via email to