more complex queries

2010-05-20 Thread Chris Withers
Hi All, I have a Transaction model with a DecimalField called "amount" and a CharField called "action". How do I sum all the transactions, multipling the amount by -1 when the action is REFUND? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting

Re: more complex queries

2010-05-20 Thread John M
Sounds like two queries to me, sum all the refunds and then subtract them from all the non-refund amounts. does that work for ya? On May 20, 5:17 pm, Chris Withers wrote: > Hi All, > > I have a Transaction model with a DecimalField called "amount" and a > CharField called "action". > > How do I

Re: more complex queries

2010-05-20 Thread Chris Withers
John M wrote: Sounds like two queries to me, sum all the refunds and then subtract them from all the non-refund amounts. does that work for ya? Not really, that requires two queries. I know this can be done in one query in SQL, just wondering how to express that in Django ORM speak... Chris

Re: more complex queries

2010-05-20 Thread Shawn Milochik
You could create your own manager and have it do whatever you want -- even run the SQL query you already want to write and still return a queryset. http://docs.djangoproject.com/en/1.1/topics/db/managers/#id2 Shawn -- You received this message because you are subscribed to the Google Groups "