RE: list? queryet? joining together

2017-01-13 Thread Mike Jones
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:

 

89…….etc

BOOKING 1 determined tool1 has a job here for 1 hourBOOKING 2 
determined that tool1 has a job heretool1 still in use…….etc 
until hours used then unbooked hoursBook… etc

 

And if there are no bookings for a tool on a day to just output rows of Book 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 
u

RE: template tag help please?

2018-08-17 Thread Mike Jones
Yes

 

For example, in the filter {{ var|foo:"bar" }}, the filter foo would be passed 
the variable var and the argument "bar".

 

I want to pass 2 (maybe 3) variables and correct me if I am wrong but 

Custom filters are just Python functions that take one or two arguments:

 

So could do  {{ var|foo:”bar, bar2” }}

or {{ var|foo:”bar” “bar2” }}   and pass 2 arguments?   The doc doesn’t specify 

 

I assume if 2 args

def cut(value, arg1, arg2):

 

?

 

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mikhailo Keda
Sent: 17 August 2018 14:43
To: Django users
Subject: Re: template tag help please?

 

Check the documentation - 
https://docs.djangoproject.com/ko/2.1/howto/custom-template-tags/

-- 
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/zG3S_9BQKMY/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/553d2ac6-cac1-4b9a-b3bd-2a4f5934ae47%40googlegroups.com
 

 .
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/5b76d50e.1c69fb81.ad6af.0d3eSMTPIN_ADDED_BROKEN%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.


RE: template tag help please?

2018-08-22 Thread Mike Jones
Ah I was just doing that to prove it was working

 

This is the actual tag

 

from django import template

from django.conf import settings

from django.utils.html import escape

from band.models import Data

 

register = template.Library()

 

@register.simple_tag

def do_cost( name, avn, avd, *args, **kwargs ):

avn = kwargs['avn']

avd = kwargs['avd']

name = kwargs['name']

val_set = Data.objects.filter(prop = name).filter(date_period=avd)

avn = 7  #this line is just for testing

if avn >= 7:

for x in val_set:

val = x.full

else:

for x in val_set:

val = x.short

return val

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andréas Kühne
Sent: 22 August 2018 15:20
To: django-users@googlegroups.com
Subject: Re: template tag help please?

 

Wait a secound, you are doing some very strange things

 

I didn't see this before.

 

You have defined the following:

@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
avn = kwargs['avn']
avd = kwargs['avd']
name = kwargs['name']
return name

 

The method has 3 parameters that you are sending to it - name, avn and avd. 
They correspond to the values sent to the method in order. So you don't need to 
use the kwargs dictionary - it's unnecessary...

You could just write:

@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
return name




Beacause you have sent the name to the method?

 

Regards,

 

Andréas

 

 

Den ons 22 aug. 2018 kl 16:09 skrev MikeKJ :

Thank you Andreas Kuhne, progress

 

So this {% load get_cost %}{% do_cost b.name avn avd %} was working quite 
happily but for some reason is now complaining 

 


Exception Type:

TemplateSyntaxError


 Exception Value:

Caught KeyError while rendering: 'avn'

 

Exception Location claims to beget_cost.py in do_cost, line 10  which is 
avn = kwargs['avn']

 

but the exception is in the template line {% load get_cost %}{% do_cost b.name 
avn avd %}

 

 

 

-- 
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/8d9d18dd-c8cb-494c-a2b8-8b06b64c40d3%40googlegroups.com
 

 .
For more options, visit https://groups.google.com/d/optout.

-- 
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/zG3S_9BQKMY/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/CAK4qSCcnJzyrWXGjTyF9NZAc0SE6zxQ1gbrd1ZM2Oc%2B3ZL_tyQ%40mail.gmail.com
 

 .
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/5b7d7953.1c69fb81.85c08.097dSMTPIN_ADDED_BROKEN%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.


RE: template tag help please?

2018-08-23 Thread Mike Jones
Andreas,  

Thank you for your help and patience I have got the damned thing working!!  

It helped that I remembered that one of the filter arguments was actually a 
foreign key in the model and had to be an integer id not a string,  that was 
being obfuscated by being a templatetag call.

 

Thank you

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andréas Kühne
Sent: 23 August 2018 08:15
To: django-users@googlegroups.com
Subject: Re: template tag help please?

 

Yes - but you still are doing it strange - you shouldn't use kwargs if you are 
sending the parameters and have the parameters in the function - use the 
parameters.

 

In other words: 

avn = kwargs['avn']

avd = kwargs['avd']

name = kwargs['name']

 

That is unnecessary




Regards,

 

Andréas

 

 

Den ons 22 aug. 2018 kl 16:55 skrev Mike Jones :

Ah I was just doing that to prove it was working

 

This is the actual tag

 

from django import template

from django.conf import settings

from django.utils.html import escape

from band.models import Data

 

register = template.Library()

 

@register.simple_tag

def do_cost( name, avn, avd, *args, **kwargs ):

avn = kwargs['avn']

avd = kwargs['avd']

name = kwargs['name']

val_set = Data.objects.filter(prop = name).filter(date_period=avd)

avn = 7  #this line is just for testing

if avn >= 7:

for x in val_set:

val = x.full

else:

for x in val_set:

val = x.short

return val

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andréas Kühne
Sent: 22 August 2018 15:20
To: django-users@googlegroups.com
Subject: Re: template tag help please?

 

Wait a secound, you are doing some very strange things

 

I didn't see this before.

 

You have defined the following:

@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
avn = kwargs['avn']
avd = kwargs['avd']
name = kwargs['name']
return name

 

The method has 3 parameters that you are sending to it - name, avn and avd. 
They correspond to the values sent to the method in order. So you don't need to 
use the kwargs dictionary - it's unnecessary...

You could just write:

@register.simple_tag
def do_cost( name, avn, avd, *args, **kwargs ):
return name




Beacause you have sent the name to the method?

 

Regards,

 

Andréas

 

 

Den ons 22 aug. 2018 kl 16:09 skrev MikeKJ :

Thank you Andreas Kuhne, progress

 

So this {% load get_cost %}{% do_cost b.name avn avd %} was working quite 
happily but for some reason is now complaining 

 


Exception Type:

TemplateSyntaxError


 Exception Value:

Caught KeyError while rendering: 'avn'

 

Exception Location claims to beget_cost.py in do_cost, line 10  which is 
avn = kwargs['avn']

 

but the exception is in the template line {% load get_cost %}{% do_cost b.name 
avn avd %}

 

 

 

-- 
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/8d9d18dd-c8cb-494c-a2b8-8b06b64c40d3%40googlegroups.com
 
<https://groups.google.com/d/msgid/django-users/8d9d18dd-c8cb-494c-a2b8-8b06b64c40d3%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 a topic in the Google 
Groups "Django users" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/django-users/zG3S_9BQKMY/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/CAK4qSCcnJzyrWXGjTyF9NZAc0SE6zxQ1gbrd1ZM2Oc%2B3ZL_tyQ%40mail.gmail.com
 
<https://groups.google.com/d/msgid/django-users/CAK4qSCcnJzyrWXGjTyF9NZAc0SE6zxQ1gbrd1ZM2Oc%2B3ZL_tyQ%40mail.gmail.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 dj