Thanks for response I’ll try to answer as below in red

 

*Subject:* Re: list? queryet? joining together

 

Hi, just a couple of follow-up questions as having trouble following 
precisely.

Can you re-state the exact queries you’re looking for?
Your comment about ‘folding’ model objects makes sense so,

 

I thought some more about it and am thinking about creating a dict of all 
bookings for a tool for the day 
Booking.objects.all().filter(resource=1).filter(date=now).order_by('start').values()
 
and now considering how to manipulate that.

Example: 

[{'name': u'Test', 'resource_id': 1L, 'hours': 6L, 'start': u'10', 'date': 
datetime.date(2017, 1, 13), 'id': 31L, 'resource_quantity_booked': 1L}, 
{'name': u'Me', 'resource_id': 1L, 'hours': 1L, 'start': u'8', 'date': 
datetime.date(2017, 1, 13), 'id': 33L, 'resource_quantity_booked': 1L}, 
{'name': u'Testing', 'resource_id': 1L, 'hours': 4L, 'start': u'9', 'date': 
datetime.date(2017, 1, 13), 'id': 32L, 'resource_quantity_booked': 1L}]

 

If it is possible to manipulate that dict (or object) to determine that 
tool1 can be expressed as a booking of 1 hour at 9 and then booked from 10 
for 6 hours and therefore the next booking has to be applied to tool2

The wrinkle is that more than 1 tool can be booked to a job but the logic 
to determine tool2 is required to accommodate booking object 3 then similar 
logic should be able to determine that if all hours are filled on 2 objects 
therefore 2 tools are required.

Kinda hoping to use this manipulated dict in the view to send html to the 
template like:

 

<tr><td>8</td><td>9</td>…….etc</tr>

<tr><td>BOOKING 1 determined tool1 has a job here for 1 
hour</td><td>BOOKING 2 determined that tool1 has a job here</td><td>tool1 
still in use</td>…….etc until hours used then unbooked hours<td><a 
href=”book?time=x&resource=1&date={{now}}”>Book</a></td>… etc

 

And if there are no bookings for a tool on a day to just output rows of 
<td><a href=”book?time=x&resource=1&date={{now}}”>Book</a></td> for the 
currently unused tools just in case another tool is required. 

 

Hope that makes better sense


- Are you looking to check if there are tools of a given type available at 
a given time? Yes, by outputting the bookings on the tools in a tabular 
format by time


- And whether a tool of a given type can be booked in a given time window? 
Yes


- When you said you wanted to “fold” 2 bookings into the same time window - 
intuitively at first glance a booking app would want to do the opposite, 
ie. find empty time windows - could you elaborate on these booking use 
cases? Is this for a single customer who wants to book multiple tools at a 
time?  I agree, kinda given up on that idea

 

‘Customer’ the shop can either use a single tool on a job for any number of 
hours in a day and could also require more than 1 tool for any number of 
hours 


- Sharing the Tool and Booking models would be useful.

class Resource(models.Model):     // various tools

    resource = models.CharField(max_length=30)

    resource_capacity = models.IntegerField()

    seating = models.IntegerField()

 

    def __unicode__(self):

        return self.resource

 

 

class Booking(models.Model):

    resource = models.ForeignKey(Resource)

    resource_quantity_booked = models.IntegerField()

    start = models.CharField(max_length=5, help_text="whole number like 8, 
9, 10, 11, 12, 13, 14, 15, 16, 17")

    hours = models.IntegerField(max_length=2, help_text="Number of hours as 
a whole number like 3")

    date = models.DateField()

 

    class Meta:

        ordering = ('date',)


This may be too basic, but for time queries if you’re not already aware 
there are the keyword lookups gt, gte (greater than, greater than or equal 
to) and lt, lte, for example:

now = timezone.now()
active_bookings_for_tool_type = Booking.objects.filter(tool__resource=2, 
start_time__lte=now, finish_time__gte=now)
and timedelta from the datetime module is useful for handling time 
intervals.

 

Aware of these keywords thanks

 


Also there are some open source django booking apps out there which look 
pretty good, for example django-booking: 
https://github.com/bitlabstudio/django-booking - could be worth looking 
into?
Unfortunately this is an old site written in 1.3.1 with a suite of custom 
tools developed for 1.3.1 and would have to be completely re-written 
entirely.. good thought though.

 
Another thought occurred that may or may not be practical as I it is just a 
thought, currently I have set up the models so a tool is assigned to a 
booking and am wondering about what the possibilities would be of reversing 
that and making a booking assigned to a tool?

-- 
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/875cfef4-928d-4c45-8880-636291bb4a98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to