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

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andrew Beales
Sent: 12 January 2017 19:52
To: Django users
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?

On Tuesday, January 10, 2017 at 3:05:33 PM UTC, MikeKJ wrote:

May be another way of doing this?

5 tools @ 9 hours = 45 hours maximum possible utilisation
1 tool = 9 hours maximum possible utilisation

each tool is a list
pa = [] (tool1)
pb = [] (tool2)  etc

max = 9
need to know the count of objects
loop all the booking objects 
use the max count as the index 
test if all booked hours exceeds max if not then list pa is complete
else
add together object hours to not exceed max and make each list pa, pb etc
ending up with 
pa = [(object, object, object)]
pb = [(object, object, object, object)]   etc
then unpack the tuples in the template with if statements to position as to 
time and duration

Would that work better?
What code would achieve it?
Appreciate any help here
        

    

-- 
You received this message because you are subscribed to a topic in the Google 
Groups "Django users" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/django-users/2VkJ-c2VgfI/unsubscribe.
To unsubscribe from this group and all its topics, 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/141e1af8-86c2-498e-b6ce-0a39a4fc3ac2%40googlegroups.com
 
<https://groups.google.com/d/msgid/django-users/141e1af8-86c2-498e-b6ce-0a39a4fc3ac2%40googlegroups.com?utm_medium=email&utm_source=footer>
 .
For more options, visit https://groups.google.com/d/optout.

-- 
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/5878bc5a.13961c0a.ad5ea.122cSMTPIN_ADDED_BROKEN%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to