Got a quantity of a type of tool to have hours booked, sometimes a tool is booked for all available hours and sometimes for only a few hours and sometimes more than 1 tool is booked to the job. The problem I am having is adding a booking into usable hours, I think I need to determine if the new booking will slip into an available existing booking, so...
[code] list = Booking.objects.all().filter(resource=2).filter(date=now).order_by("-resource_quantity_booked") //resource is the type of tool // break the list into the individual tools ( of which there are 5 available) for x in list: plist[x] = {'id': x.id, 'list': list} plist = list(plist) try: pa = plist[0] except: pa = "" try: pb = plist[1] except: pb = "" try: pc = plist[2] except: pc = "" try: pd = plist[3] except: pd = "" try: pe = plist[4] except: pe = "" //ok got all indivdual tools // lets assume that tool pb and pc are fully utilised for all available hours and that tool pa is booked for 4 hours from 10am (10:00 to 14:00) // therefore there are 2 potential available hours before availble and four hours after the booking for tool pa //lets assume that a booking is made for 16:00 (pd as being the 4th booking object) // so I want to fold the booking for 16:00 into the previous booking for 10:00 to ustilise the available hours //so I tried this if pd: if int(pd.start) < int(pa.start) and (pd.hours < (int(pa.start)-8)): //looking for prior availability pass //wip if int(pd.start) > (pa.hours + int(pa.start)) and (pd.hours <= (18-pd.hours+int(pd.start))): // this shows that there is availability from itertools import chain #pa = list(chain(pa, pd)) #pa.extend(pd) from django.db.models import Q yy = Q(pa) | Q(pd) //result (OR: Booking object, Booking object) papd = chain(pa, pd) //result <itertools.chain object at 0x7f5d7d37a9d0> // need to empty pd as it is now part of pa? [/code] yy appears to be the result I want ( 2 objects (or more)) joined How do I get at the individual objects within yy in a template? Is there a better way to do this? -- 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/9f1c864b-d5a4-42ec-bf6c-8e6124792ba3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.