Re: Django case, when, then on querysets

2014-05-14 Thread Anthony
But a query isn't run until I actually do something with the object, by loading it into memory by accessing or iterating over a queryset I'm performing potential time consuming operations. Isn't it better to do whatever work I can on the database? In some cases I could be doing something similar

Re: Django case, when, then on querysets

2014-05-14 Thread Daniel Roseman
On Wednesday, 14 May 2014 01:20:39 UTC+1, Anthony Hawkes wrote: > > Thanks for the answer! Do you think it would be practical to let the orm > generate the base query and then doing a replace on the column name? I was > thinking of this approach as a custom manager method to return a raw result.

Re: Django case, when, then on querysets

2014-05-13 Thread Anthony
Thanks for the answer! Do you think it would be practical to let the orm generate the base query and then doing a replace on the column name? I was thinking of this approach as a custom manager method to return a raw result. This would allow me the generate a case statement for the column and I

Re: Django case, when, then on querysets

2014-05-13 Thread Tom Evans
On Tue, May 13, 2014 at 11:04 PM, Anthony wrote: > Basically when a queryset like > instance.annotate(totals=Count('item_description')[:3] like > PC 10 > Mac 7 > Mouse 5 > Keyboard 4 > > I want to combine PC and Mac as say: Desktop so the results become > > Desktop 17 >

Re: Django case, when, then on querysets

2014-05-13 Thread Anthony
Basically when a queryset like instance.annotate(totals=Count('item_description')[:3] like PC 10 Mac 7 Mouse 5 Keyboard 4 I want to combine PC and Mac as say: Desktop so the results become Desktop 17 Mac 7 Mouse 5 Keyboard 4 Scanner 3 Ant On 14/05/2014 4:45 AM, "Tom Evans"

Re: Django case, when, then on querysets

2014-05-13 Thread Tom Evans
On Tue, May 13, 2014 at 1:00 AM, Anthony Hawkes wrote: > Hi Guys, > > I need to replace results in a queryset and then perform counts and further > queries on the set and have been trying to find a way of doing it. What do you mean by "replace results"? > > Basically in

Django case, when, then on querysets

2014-05-12 Thread Anthony Hawkes
Hi Guys, I need to replace results in a queryset and then perform counts and further queries on the set and have been trying to find a way of doing it. Basically in some but not all cases I get a set of results eg select * from table and then I want to do a: case when column = 'some value'