Re: Using Sum() for a models method inside a Query

2014-11-24 Thread monoBOT
You can also do that using the ORM instead of SQL, just instead of doing the calls on the instanced model use a manager and do the calls on all the objects in the database, something like this: class Objectmanager(models.Manager): def SumAB(self): return sum([(obj.a + obj.b) for obj

Re: Using Sum() for a models method inside a Query

2014-11-24 Thread Jorge Andrés Vergara Ebratt
Thanks, the best bet is the raw query, because I actually need the Sum of the method result for all the instances in the query... 2014-11-24 3:52 GMT-05:00 monoBOT : > You can create a model method (with no parameter) that can solve that, so > you can call it from the

Re: Using Sum() for a models method inside a Query

2014-11-24 Thread monoBOT
You can create a model method (with no parameter) that can solve that, so you can call it from the templates. something like: class MyObject(models.Model): a = models.IntegerField() b = models.Integerfield() def miOperation(self): return self.a + self.b def

Re: Using Sum() for a models method inside a Query

2014-11-23 Thread Ethan Blackburn
related: https://groups.google.com/forum/#!topic/django-users/s9qgXC4TNrA Short answer: you can't. A raw query would be your best bet(i.e. "SELECT SUM(a + b) AS sum FROM app_X") On Sunday, November 23, 2014 4:42:48 PM UTC-6, Jorge Andrés Vergara Ebratt wrote: > > Hello everyone, > > Well, the

Re: Using Sum() for a models method inside a Query

2014-11-23 Thread Vijay Khemlani
What do you mean by the sum or average of the method? As in the sum or average of the method applied to a list of objects "X"? On Sun, Nov 23, 2014 at 7:41 PM, Jorge Andrés Vergara Ebratt < javebr...@gmail.com> wrote: > Hello everyone, > > Well, the tittle says it all: > > I have a model X > >

Using Sum() for a models method inside a Query

2014-11-23 Thread Jorge Andrés Vergara Ebratt
Hello everyone, Well, the tittle says it all: I have a model X class X(models.Model) a = models.IntegerField() b = models.IntegerField() def getC(self): return a + b So, when I'm inside a template I can call {{x.getC}} and it gets the method for the current instance it's in, but