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 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/CAFHbX1J-NT2R5WxHeS6Qaw_ZjZCn6N4g%3DcP6Ta8gVE3MqsBP7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to