Re: Calculations

2023-07-10 Thread Abdou KARAMBIZI
Thanks Thomas, now it is working properly On Mon, Jul 10, 2023 at 12:17 PM Thomas Couch wrote: > Ah ok, looks like aggregate always returns a dictionary. This should work: > > outstanding_balance = loan.amount_to_pay - > loan.payments_set.aggregate(paid=Sum("amount"))['paid'] > > On Monday, July

Re: Calculations

2023-07-10 Thread Thomas Couch
Ah ok, looks like aggregate always returns a dictionary. This should work: outstanding_balance = loan.amount_to_pay - loan.payments_set.aggregate(paid=Sum("amount"))['paid'] On Monday, July 10, 2023 at 11:03:06 AM UTC+1 Abdou KARAMBIZI wrote: > Hello Thomas > > I have tried but I got that erro

Re: Calculations

2023-07-10 Thread Abdou KARAMBIZI
Hello Thomas I have tried but I got that error message On Fri, Jul 7, 2023 at 5:03 PM Thomas Couch wrote: > Hi Abdou, have a look at aggregation ( > https://docs.djangoproject.com/en/4.2/topics/db/aggregation/) > > In this case I think you'll want something like: > > ``` > from django.db.models

Re: Calculations

2023-07-08 Thread Clement Idemudo
in addition to what @Thomas said you need to first perform an aggregated sum on the payments model hence the need for ... loan.payments_set.aggregrate(models.Sum('amount')) the above returns the sum of all payment related to your loan instance from which you can now subtract from loan.amount_to_

Re: Calculations

2023-07-07 Thread Thomas Couch
Or, you can combine annotations and expressions to do something like this: qs = LoanInformation.objects.annotate(outstanding=F("amount_to_pay") - Func(F("payments__amount"), function="SUM)) loan = qs.get(id=loan_id) loan.outstanding On Friday, July 7, 2023 at 4:03:09 PM UTC+1 Thomas Couch wrote:

Re: Calculations

2023-07-07 Thread Thomas Couch
Hi Abdou, have a look at aggregation (https://docs.djangoproject.com/en/4.2/topics/db/aggregation/) In this case I think you'll want something like: ``` from django.db.models import Sum # Where loan = the LoanInformation instance you're interested in outstanding_balance = loan.amount_to_pay -

Re: Calculations Between Models

2022-04-21 Thread techg...@gmail.com
Hello Derek, Your solution worked, I appreciated the help. Regards. On Wednesday, April 20, 2022 at 5:50:25 PM UTC+3 Derek wrote: > Not sure what the "@aproperty" are here for, but in your views.py file, > you could do this calculation, passing in the ID of the staff record: > > from .models i

Re: Calculations Between Models

2022-04-20 Thread Derek
Not sure what the "@aproperty" are here for, but in your views.py file, you could do this calculation, passing in the ID of the staff record: from .models import Staff, LeaveReportStaff def get_leave_balance(staff_id): total_leave_days = Staff.objects.get(pk=staff_id) leave_reports = Lea

Calculations Between Models

2022-04-19 Thread tech george
Hello, I have a model Staff and LeaveReportStaff, I wanted to get leave_balance between Total_Leave_Days and leave_days. Please advise the best way forward. class Staff(models.Model): Total_Leave_Days = models.PositiveIntegerField(default=0) course = models.ForeignKey(Course, on_delete=m

How to do calculations in Model

2021-09-15 Thread joji...@gmail.com
Hello there, I am creating a salary & payroll application in Django. I need your guidance in calcuating the salary and insert to salarydetails table. I wanted to know how we can do the calculation using models. For example first we need to calculate the salary details for each salary head after

Re: Can I perform calculations directly in django tags/filters?

2019-12-18 Thread Luqman Shofuleji
Try using django-mathfilters. https://pypi.org/project/django-mathfilters/ On Wed, Dec 18, 2019, 11:55 PM Adeotun Adegbaju wrote: > you should indicate which files codes should be added to > > On Tuesday, November 18, 2008 at 11:21:09 PM UTC+1, Daniel Roseman wrote: >> >> On Nov 18, 7:55 pm, ja

Re: Can I perform calculations directly in django tags/filters?

2019-12-18 Thread Adeotun Adegbaju
you should indicate which files codes should be added to On Tuesday, November 18, 2008 at 11:21:09 PM UTC+1, Daniel Roseman wrote: > > On Nov 18, 7:55 pm, jago wrote: > > I am thinking about something like {{ (width - 5) *12 }} ? > > No. You can add or subtract using the 'add' filter: > {{

Django Opening Balance Calculations

2019-02-05 Thread mintuser701
I am trying to create a simple inventory app using Django. My project came to a stand still when I couldn't find a solution for calculating opening and closing balances on the fly/dynamically. I tried for days researching on the web but no progress yet. If anyone could help i will appreciat

help get the value of field from the admin in Django to perform some calculations

2017-12-25 Thread Atef Ouerghi
How can I get the value of field from the admin in Django to perform some calculations -- 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-user

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-24 Thread Pepsodent Cola
On Wednesday, November 20, 2013 10:29:24 PM UTC+1, Pepsodent Cola wrote: > > 1.) > How do I use mathematical calculations on my forloop Article/Publication > list? > > * I have attached a screenshot with the table field that I'm working on > *"Publicists > co

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-23 Thread Andre Terra
_publications }} > ({{ row.num_publications }} / {{ total_publicists }}) = {{ > publicists_coverage }}x % > > {% endfor %} > > {% else %} > No Articles or Ziplist are available. > {% endif %} > > > > > > > > > On Wednesday, N

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-23 Thread Pepsodent Cola
%} {{ row.id }} {{ row.headline }} {{ row.num_publications }} ({{ row.num_publications }} / {{ total_publicists }}) = {{ publicists_coverage }}x % {% endfor %} {% else %} No Articles or Ziplist are available. {% endif %} On Wednesday, Novem

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-22 Thread DJ-Tom
passing only a *single* value for *publicists_coverage *to the template - why do you expect to get a different value on each loop? Currently there is no built-in way to do more than simple calculations via the "add" filter in templates, but you can easily create your own filters: http://sta

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-21 Thread Pepsodent Cola
@James Now I understand what you mean. :) I will work on this some more tonight. On Wednesday, November 20, 2013 10:29:24 PM UTC+1, Pepsodent Cola wrote: > > 1.) > How do I use mathematical calculations on my forloop Article/Publication > list? > > * I have attached a s

Re: How do I use mathematical calculations on my forloop Article/Publication list?

2013-11-21 Thread James Turley
t the set itself. articles[0].num_publications() would return the number of publications associated with the first article in the set, for example. James On Wed, Nov 20, 2013 at 9:29 PM, Pepsodent Cola wrote: > 1.) > How do I use mathematical calculations on my forloop Article/Publica

Re: Calculations in Queries

2012-08-16 Thread akaariai
On 16 elo, 03:51, Callum Bonnyman wrote: > I've tried a few things but i cannot get the correct date formats to > calculate the difference, so far i have this: > >     popular_posts = Post.objects.extra(select={ >     'popularity': '(' + datetime.datetime.now() + ' - created) * views' >     }) >

Re: Calculations in Queries

2012-08-15 Thread Sandeep kaur
On Thu, Aug 16, 2012 at 2:31 AM, Callum Bonnyman wrote: > I am creating a popular page for my app and for the most part this is just > to gain an understanding. > Any ideas? I know its something to do with query expressions and looking at > this page confuses the hell out of me. Any guidelines, o

Re: Calculations in Queries

2012-08-15 Thread Kurtis Mullins
On Wed, Aug 15, 2012 at 8:51 PM, Callum Bonnyman wrote: > I've tried a few things but i cannot get the correct date formats to > calculate the difference, so far i have this: > > popular_posts = Post.objects.extra(select={ > 'popularity': '(' + datetime.datetime.now() + ' - created) * view

Re: Calculations in Queries

2012-08-15 Thread Callum Bonnyman
I've tried a few things but i cannot get the correct date formats to calculate the difference, so far i have this: popular_posts = Post.objects.extra(select={ 'popularity': '(' + datetime.datetime.now() + ' - created) * views' }) It shows an error, i've tried googling it but not had

Re: Calculations in Queries

2012-08-15 Thread Melvyn Sopacua
On 15-8-2012 23:01, Callum Bonnyman wrote: > > > I am creating a popular page for my app and for the most part this is just > to gain an understanding. > > The idea is to divide the number of views by the days old, now i don't know > if this will be successful or even working but like I said i

Calculations in Queries

2012-08-15 Thread Callum Bonnyman
I am creating a popular page for my app and for the most part this is just to gain an understanding. The idea is to divide the number of views by the days old, now i don't know if this will be successful or even working but like I said its go get an idea of how queries work... My fields are

Re: Returning values from calculations done by custom methods in models

2012-02-18 Thread Gchorn
Whoops, wow that really was basic Python. Sorry for the spam; of course I know there's a difference between calling a method and calling an attribute...how embarassing. =) Thanks for your help Anssi. Also thanks for not adding, ", you moron!" to the end of each sentence... On Feb 19, 9:47 am, a

Re: Returning values from calculations done by custom methods in models

2012-02-18 Thread akaariai
On Feb 19, 3:38 am, Gchorn wrote: > Hello All, > > So in my models.py file, I have: > > class Player(models.Model): >         team = models.ForeignKey(Team) >         first_name = models.CharField(max_length=100) >         last_name = models.CharField(max_length=100) >         gp = models.IntegerF

Returning values from calculations done by custom methods in models

2012-02-18 Thread Gchorn
Hello All, So in my models.py file, I have: class Player(models.Model): team = models.ForeignKey(Team) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) gp = models.IntegerField(max_length=2) #games played mp = model

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-21 Thread Sean Wallace
Hi Trevor, On Fri, Jan 21, 2011 at 1:47 PM, Trevor Stanley wrote: > def get_fringe_value(self, fringe): should be def get_fringe_value(self): I don't think you are using the local variable "fringe" anywhere in this method, so you should get rid of it. and > self.fringe_total = self.f

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-21 Thread Trevor Stanley
Kenneth I have tried your line and I also removed the call to ('qft') on the fringe_value. I now get this error. I'm sure there must be something fundamentally wrong with my approach what am I missing!?! Model changed to: def get_fringe_value(self, fringe): """select record by ID fr

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-21 Thread Trevor Stanley
Rainy Thanks for the feedback and I'm sure you are right that the line is incorrect. However I need a bit of instruction. I have read extensively over the last year but I think I must be missing a fundamental thing. This is the first programming I've ever done so you may need to spell it o

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Kenneth Gonsalves
On Fri, 2011-01-21 at 07:33 +0530, Kenneth Gonsalves wrote: > On Thu, 2011-01-20 at 19:04 +, Trevor Stanley wrote: > > ft = Fringe.objects.select_related().filter(id=self.id).values() > > AttributeError: 'str' object has no attribute 'id' > > maybe filter(id=self.fringe) or (id=self.fringe_id

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Kenneth Gonsalves
On Thu, 2011-01-20 at 19:04 +, Trevor Stanley wrote: > ft = Fringe.objects.select_related().filter(id=self.id).values() > AttributeError: 'str' object has no attribute 'id' maybe filter(id=self.fringe) or (id=self.fringe_id) -- regards KG http://lawgon.livejournal.com Coimbatore LUG rox http

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Rainy
On Jan 20, 2:04 pm, Trevor Stanley wrote: > Kenneth > > That is what I originally though but if I write that this is the error I > get: > > in _get_fringe_value >     ft = Fringe.objects.select_related().filter(id=self.id).values() > AttributeError: 'str' object has no attribute 'id' > > I'm in

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Trevor Stanley
Kenneth That is what I originally though but if I write that this is the error I get: in _get_fringe_value ft = Fringe.objects.select_related().filter(id=self.id).values() AttributeError: 'str' object has no attribute 'id' I'm in London and I do this in my spare time so have just arrived h

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Kenneth Gonsalves
On Thu, 2011-01-20 at 08:37 +, Trevor Stanley wrote: > Fringe.objects.select_related().filter(id=self) should this not be (id=self.id) -- regards KG http://lawgon.livejournal.com Coimbatore LUG rox http://ilugcbe.techstud.org/ -- You received this message because you are subscribed to the G

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-20 Thread Trevor Stanley
Kenneth Gonsalves wrote: On Wed, 2011-01-19 at 22:34 +, The Stanley Household wrote: Happy to send Model if needed but at the moment I'm unable to run the server to provide admin error report, can C&P from terminal if that would help with the error. please copy and paste your code

Re: Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-19 Thread Kenneth Gonsalves
On Wed, 2011-01-19 at 22:34 +, The Stanley Household wrote: > Happy to send Model if needed but at the moment I'm unable to run the > server to provide admin error report, can C&P from terminal if that > would help with the error. please copy and paste your code - it is easier for us to help

Can someone help with Many-to-many referencing and then calculations against another field on the linked model

2011-01-19 Thread The Stanley Household
Dear whoever is out there This is my first e-mail to any kind of group. I am also new to all the concepts of programming, SQL, Python and Django. I've worked quite hard over the last six months to try an teach myself all these things. I am now writing an App and need some help with some calcula

Re: speed of calculations - combining query improves speed?

2009-12-11 Thread Daniel Roseman
On Dec 11, 2:22 pm, mbdtsmh wrote: > Hi all - can someone put me out of my misery on this one please? > > I have a piece of code that uses the request.GET keys in the url to > produce the following in my views.py > > objects = Issue.objects.all() > objects = objects.filter > (designset__project__R

speed of calculations - combining query improves speed?

2009-12-11 Thread mbdtsmh
Hi all - can someone put me out of my misery on this one please? I have a piece of code that uses the request.GET keys in the url to produce the following in my views.py objects = Issue.objects.all() objects = objects.filter (designset__project__RA__RA=request.GET.__getitem__('RA')).distinct() ob

Re: Selecting date formats for aggregate calculations from database with Django

2009-04-09 Thread Russell Keith-Magee
On Fri, Apr 10, 2009 at 5:23 AM, Andrew C wrote: > > I would like to do aggregate calculations based on month for a > datetime field. This feature request has been made before; it's logged as ticket #10302. > I am currently using the extra() function to format the date l

Selecting date formats for aggregate calculations from database with Django

2009-04-09 Thread Andrew C
I would like to do aggregate calculations based on month for a datetime field. I am currently using the extra() function to format the date like: ...extra(select="strftime('column', '%m/%Y') as t").values ('t').annotate(SUM(foo)) and it works great for

Re: Can I perform calculations directly in django tags/filters?

2008-11-18 Thread Daniel Roseman
On Nov 18, 7:55 pm, jago <[EMAIL PROTECTED]> wrote: > I am thinking about something like {{  (width - 5) *12  }}  ? No. You can add or subtract using the 'add' filter: {{ width:add:"-5" }} but anything else will require a custom template tag or filter. Luckily, these are extremely easy to write:

Re: Can I perform calculations directly in django tags/filters?

2008-11-18 Thread DavidA
You can do it in a custom eval-like tag: @register.tag() def evalpy(parser, token): try: tag_name, expression = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split(

Re: Can I perform calculations directly in django tags/filters?

2008-11-18 Thread Rajesh Dhawan
> I am thinking about something like {{  (width - 5) *12  }}  ? No. That syntax is not supported in Django templates. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

Can I perform calculations directly in django tags/filters?

2008-11-18 Thread jago
I am thinking about something like {{ (width - 5) *12 }} ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe fro

Re: doing calculations

2007-01-23 Thread Kenneth Gonsalves
On 23-Jan-07, at 6:55 PM, Ramdas S wrote: > Now I need to calculate the netrate, and see that every time a bill > is saved, it is stored automagically in the netrate field. if the netrate is solely dependent only on other fields in the same model, do you need to save it? -- regards kg ht

Re: doing calculations

2007-01-23 Thread Jam
If the "netrate" value is calculated, why don't you simply add a "netrate" method to your class ? def netrate(self): return no_of_units * price* (1+ taxes/100) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "D

Re: doing calculations

2007-01-23 Thread ashwoods
ah, me too slow :) On Jan 23, 2:40 pm, "ashwoods" <[EMAIL PROTECTED]> wrote: > yes, you would override the save methods. > look at :http://www.djangoproject.com/documentation/model_api/ > (Overriding default model methods) > > applied to your example, it would look something like this... > > clas

Re: doing calculations

2007-01-23 Thread ashwoods
yes, you would override the save methods. look at :http://www.djangoproject.com/documentation/model_api/ (Overriding default model methods) applied to your example, it would look something like this... class Model(models.Model): bla bla... def netratefunction(self): bla bla bla

Re: doing calculations

2007-01-23 Thread Jonathan Buchanan
On 1/23/07, Ramdas S <[EMAIL PROTECTED]> wrote: > I am simplyfying a rather complex model I have here, so that some one can > give me the right advice. > > I have a class called Bill > > class Bill(models.Model): > no_of_units = models.IntegerField() > price= models.FloatFiled(max_

doing calculations

2007-01-23 Thread Ramdas S
I am simplyfying a rather complex model I have here, so that some one can give me the right advice. I have a class called Bill class Bill(models.Model): no_of_units = models.IntegerField() price= models.FloatFiled(max_digits=5, decimal_places=1) taxes = models.FloatFie

Re: In Model or Manager? (Sorting, calculations, and non-savable fields)

2007-01-10 Thread ringemup
Thanks, that helps. I like that there are multiple ways to do things. Hopefully with a little more experience I'll have a better idea of where to put things for best re-usability. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

Re: In Model or Manager? (Sorting, calculations, and non-savable fields)

2007-01-04 Thread Brian Beck
Brian Beck wrote: class Payment(models.Model): ... class Custom: def sortable_fields = ['amount', 'received_date'] That last line should of course just be: sortable_fields = ['amount', 'received_date'] --~--~-~--~~~---~--~~ You received t

Re: In Model or Manager? (Sorting, calculations, and non-savable fields)

2007-01-04 Thread Brian Beck
a query. Sure, you could add these things there, but it breaks this convention. So, here's my recommendation: - Non-saveable fields: Use a custom class attribute or method (these aren't instance-specific, right?). - Calculations: Most likely this performs a query. Put it in the manager.

Re: In Model or Manager? (Sorting, calculations, and non-savable fields)

2007-01-02 Thread ringemup
Right, it makes sense to put display logic in the views/templates. And of course, the actual building of the tables will go there. Does that apply to the actual sorting of the data as well? It seems to me that it's something most efficiently accomplished at the database level. And then... wha

Re: In Model or Manager? (Sorting, calculations, and non-savable fields)

2007-01-01 Thread Jacob Kaplan-Moss
On 12/31/06 12:33 PM, ringemup wrote: I'm working on a fairly data-heavy (as opposed to content-heavy) application, and I'm trying to create some reusable code for sortable HTML tables ^^^ ... Or does this belong somewhere else entirely (like a specialized method for each view)?

In Model or Manager? (Sorting, calculations, and non-savable fields)

2006-12-31 Thread ringemup
Hi folks, I'm working on a fairly data-heavy (as opposed to content-heavy) application, and I'm trying to create some reusable code for sortable HTML tables (not relying on Javascript, since there are a number of drawbacks to that). I'd like each model to be able to provide a list of columns it