Basically when a queryset like
instance.annotate(totals=Count('item_description')[:3] like
PC 10
Mac 7
Mouse 5
Keyboard 4I 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" <[email protected]> wrote: > On Tue, May 13, 2014 at 1:00 AM, Anthony Hawkes <[email protected]> > 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 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' then 'some > > other value'. > > > > Is there any way using django's queries or at least preserving the > ability > > to continue using the queries using raw sql? (I've had a look at extra() > but > > can't see a way to make it work) > > > > I'm not really sure what any of this means.. > > Let me throw some sample code at you > > qs = Model.objects.all() > if foo: > qs = qs.filter(column='some value') > else: > qs = qs.filter(column_b='some other value') > num_results = qs.count() > > Is that what you are after? > > Cheers > > Tom > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/ZuSxc3YXA3c/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAFHbX1J-NT2R5WxHeS6Qaw_ZjZCn6N4g%3DcP6Ta8gVE3MqsBP7Q%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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABqJoT2WnE5v7odhPAoYM%3DEURd3u%3D%2BzqF24MQOHKtDbKYX0kcw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

