python django fields and row calculation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

python django fields and row calculation

sum abiut
Hi,

I am working on an leave management system and I am having a some difficulties trying to figure out how to accomplished this scenario.

for example i have a table of.

when a user apply for a leave i want to get the previous total_leave_balance of the applicant and minus his/her current num_days and assign the result to be the total_leave_balance. Please advise what would be the best way to approach this.


username first_name second_name num_days leave_entitlement beginning_bal Total_leave_balance
jtom james tom 3 12 23 20
tjohn tom john 2 2 5 7
atom anna tom 3 21 2

jtom james tom 3 4 2

atom anna tom 3 3 5



cheers,

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y562uvxRwTf0iFnT6Lcos8_nd3FD5u%3D7MVVp2yN4qAcDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: python django fields and row calculation

Lachlan Musicman
Depends on your models, but write a small function that returns the balance?

def balance(self):
    return self.entitlement - self.num_days


(for instance)

L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 10:49, sum abiut <[hidden email]> wrote:
Hi,

I am working on an leave management system and I am having a some difficulties trying to figure out how to accomplished this scenario.

for example i have a table of.

when a user apply for a leave i want to get the previous total_leave_balance of the applicant and minus his/her current num_days and assign the result to be the total_leave_balance. Please advise what would be the best way to approach this.


username first_name second_name num_days leave_entitlement beginning_bal Total_leave_balance
jtom james tom 3 12 23 20
tjohn tom john 2 2 5 7
atom anna tom 3 21 2

jtom james tom 3 4 2

atom anna tom 3 3 5



cheers,

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y562uvxRwTf0iFnT6Lcos8_nd3FD5u%3D7MVVp2yN4qAcDA%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiN6th0dJWHTN0R--sehmD0B--DzbzUV6a5mXOLfz_5MHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: python django fields and row calculation

sum abiut
Thank for taking your time to respond. my problem is automating that, for example when a user apply for a leave i want the system to calculate and update the total balance automatically. But Since a user can apply for a leave more that once which mean a user can have more that one record of leave application on the database. My problem is having to figure out when was the last time that the user has launch his/her leave application so that i can minus num_days from the that total balance.


thanks

 

On Wed, Apr 5, 2017 at 12:20 PM, Lachlan Musicman <[hidden email]> wrote:
Depends on your models, but write a small function that returns the balance?

def balance(self):
    return self.entitlement - self.num_days


(for instance)

L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 10:49, sum abiut <[hidden email]> wrote:
Hi,

I am working on an leave management system and I am having a some difficulties trying to figure out how to accomplished this scenario.

for example i have a table of.

when a user apply for a leave i want to get the previous total_leave_balance of the applicant and minus his/her current num_days and assign the result to be the total_leave_balance. Please advise what would be the best way to approach this.


username first_name second_name num_days leave_entitlement beginning_bal Total_leave_balance
jtom james tom 3 12 23 20
tjohn tom john 2 2 5 7
atom anna tom 3 21 2

jtom james tom 3 4 2

atom anna tom 3 3 5



cheers,

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y562uvxRwTf0iFnT6Lcos8_nd3FD5u%3D7MVVp2yN4qAcDA%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiN6th0dJWHTN0R--sehmD0B--DzbzUV6a5mXOLfz_5MHg%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y5CNSJacdxNqL%2Bxwa0LkjAvsoT%3D1%2B384hNJ0KxfhGi87A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: python django fields and row calculation

Lachlan Musicman
Well, if it's on the user model as a function, then it will happen as soon as you call it.

If they can have mulitple applications in process, then you will need to program your function(s) to account for that.

As they say "there's more than one way to do it".

You could add a "remaining days" var to the user model and store the info in there secretly.
You could get the function to programmatically work through the applications for the user in the order in which they have been received?
...

cheers
L.


------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 13:21, sum abiut <[hidden email]> wrote:
Thank for taking your time to respond. my problem is automating that, for example when a user apply for a leave i want the system to calculate and update the total balance automatically. But Since a user can apply for a leave more that once which mean a user can have more that one record of leave application on the database. My problem is having to figure out when was the last time that the user has launch his/her leave application so that i can minus num_days from the that total balance.


thanks

 

On Wed, Apr 5, 2017 at 12:20 PM, Lachlan Musicman <[hidden email]> wrote:
Depends on your models, but write a small function that returns the balance?

def balance(self):
    return self.entitlement - self.num_days


(for instance)

L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 10:49, sum abiut <[hidden email]> wrote:
Hi,

I am working on an leave management system and I am having a some difficulties trying to figure out how to accomplished this scenario.

for example i have a table of.

when a user apply for a leave i want to get the previous total_leave_balance of the applicant and minus his/her current num_days and assign the result to be the total_leave_balance. Please advise what would be the best way to approach this.


username first_name second_name num_days leave_entitlement beginning_bal Total_leave_balance
jtom james tom 3 12 23 20
tjohn tom john 2 2 5 7
atom anna tom 3 21 2

jtom james tom 3 4 2

atom anna tom 3 3 5



cheers,

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y562uvxRwTf0iFnT6Lcos8_nd3FD5u%3D7MVVp2yN4qAcDA%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiN6th0dJWHTN0R--sehmD0B--DzbzUV6a5mXOLfz_5MHg%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y5CNSJacdxNqL%2Bxwa0LkjAvsoT%3D1%2B384hNJ0KxfhGi87A%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiOv8VgHj7-BheSY9fHh2Y6eQk4JRv-oRFT49jQ_k7x%2BFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: python django fields and row calculation

sum abiut
Thanks heaps this should get me started

On Wed, Apr 5, 2017 at 2:42 PM, Lachlan Musicman <[hidden email]> wrote:
Well, if it's on the user model as a function, then it will happen as soon as you call it.

If they can have mulitple applications in process, then you will need to program your function(s) to account for that.

As they say "there's more than one way to do it".

You could add a "remaining days" var to the user model and store the info in there secretly.
You could get the function to programmatically work through the applications for the user in the order in which they have been received?
...

cheers
L.


------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 13:21, sum abiut <[hidden email]> wrote:
Thank for taking your time to respond. my problem is automating that, for example when a user apply for a leave i want the system to calculate and update the total balance automatically. But Since a user can apply for a leave more that once which mean a user can have more that one record of leave application on the database. My problem is having to figure out when was the last time that the user has launch his/her leave application so that i can minus num_days from the that total balance.


thanks

 

On Wed, Apr 5, 2017 at 12:20 PM, Lachlan Musicman <[hidden email]> wrote:
Depends on your models, but write a small function that returns the balance?

def balance(self):
    return self.entitlement - self.num_days


(for instance)

L.

------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 5 April 2017 at 10:49, sum abiut <[hidden email]> wrote:
Hi,

I am working on an leave management system and I am having a some difficulties trying to figure out how to accomplished this scenario.

for example i have a table of.

when a user apply for a leave i want to get the previous total_leave_balance of the applicant and minus his/her current num_days and assign the result to be the total_leave_balance. Please advise what would be the best way to approach this.


username first_name second_name num_days leave_entitlement beginning_bal Total_leave_balance
jtom james tom 3 12 23 20
tjohn tom john 2 2 5 7
atom anna tom 3 21 2

jtom james tom 3 4 2

atom anna tom 3 3 5



cheers,

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y562uvxRwTf0iFnT6Lcos8_nd3FD5u%3D7MVVp2yN4qAcDA%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiN6th0dJWHTN0R--sehmD0B--DzbzUV6a5mXOLfz_5MHg%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y5CNSJacdxNqL%2Bxwa0LkjAvsoT%3D1%2B384hNJ0KxfhGi87A%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAGBeqiOv8VgHj7-BheSY9fHh2Y6eQk4JRv-oRFT49jQ_k7x%2BFg%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 [hidden email].
To post to this group, send email to [hidden email].
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/CAPCf-y5DZ7fE7amLgMP%3D23CciNsFp2HEzHSLCCtVg%2B9c1jp-%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: python django fields and row calculation

ijazz jazz
In reply to this post by sum abiut
In short, a model's manager is an object through which Django models perform ... (For row-level functionality – i.e., functions that act on a single instance of a model object ... This has a single method, title_count() , which does the calculation.


--
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 [hidden email].
To post to this group, send email to [hidden email].
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/39949ce2-4cc6-41e2-acf7-68c484c19c04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.