Re: Negate querysets

2010-03-24 Thread Vinicius Mendes | meiocodigo.com
Ok. I thought it was more simple. I don't know the ORM in deep and forgot about the extra() method. Thanks for the explanation. On Mar 23, 5:15 pm, James Bennett wrote: > On Tue, Mar 23, 2010 at 10:21 AM, Vinicius Mendes | meiocodigo.com > > wrote: > > integrated to the framework. I think the qu

Re: Negate querysets

2010-03-23 Thread James Bennett
On Tue, Mar 23, 2010 at 10:21 AM, Vinicius Mendes | meiocodigo.com wrote: > integrated to the framework. I think the queryset should keep track of > it self. It knows what is the filter, so why can't it negate this > filter? Given an already-existing QuerySet which has already had all the filters

Re: Negate querysets

2010-03-23 Thread Phlip
> I want to be able to answer your question, forever. Is there a way, > from a developer test, to query "what SQL statement does this QuerySet > generate"? Oh, duh, it's QuerySet.query, as a string. Brand X makes that one inconceivably hard, due to poor factoring... > -- >   Phlip >  http://c2.c

Re: Negate querysets

2010-03-23 Thread Phlip
Matt Schinckel wrote: > Are you sure it hits the db twice? Of course not. But (modulo "Premature Optimization") I would be suspicious of any such statement, as I wrote it. I want to be able to answer your question, forever. Is there a way, from a developer test, to query "what SQL statement does

Re: Negate querysets

2010-03-23 Thread Vinicius Mendes | meiocodigo.com
Matt, I know I can do this, but if I want to write a generic view that receives a queryset and deletes everything that isn't in this queryset? I'm not having this problem right now. I just thought that this was a feature that would be interesting to have in the ORM. And I am asking if it already e

Re: Negate querysets

2010-03-23 Thread Paulo Almeida
Is there some way you can keep track of the queryset? I understand it's dynamic, and maybe complex, for you to be looking for this kind of solution, but if it were possible to have a variable or dictionary keeping track of what you add to the queryset, it might be possible to use it to build the in

Re: Negate querysets

2010-03-23 Thread Matt Schinckel
On Mar 23, 11:23 pm, "Vinicius Mendes | meiocodigo.com" wrote: > Ok. The code proposed by Tim Shaffer works and gives only one query. > But it makes use of subselects, what is heavy for the database. Take a > look at the generated SQL: > > 'SELECT `auth_user`.`id`, `auth_user`.`username`, > `auth_

Re: Negate querysets

2010-03-23 Thread Vinicius Mendes | meiocodigo.com
Ok. The code proposed by Tim Shaffer works and gives only one query. But it makes use of subselects, what is heavy for the database. Take a look at the generated SQL: 'SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_use

Re: Negate querysets

2010-03-22 Thread Tim Shaffer
It depends. This will only run one query, when negated_queryset is used. queryset = User.objects.filter(first_name='vinicius') negated_queryset = User.objects.exclude(id__in=queryset.values("id")) Since the first queryset is not evaluated until it's used in the negated_queryset (as a subquery).

Re: Negate querysets

2010-03-22 Thread Matt Schinckel
On Mar 23, 6:17 am, Phlip wrote: > > Just create another queryset that excludes everything in your first > > queryset: > > > negated_queryset = User.objects.exclude(id__in=queryset.values("id")) > > QuerySets are already so easy to plug-n-play... Ain't there a way to > do it without whacking the d

Re: Negate querysets

2010-03-22 Thread Tim Shaffer
Might be possible. I'm not terribly familiar with the innards of the QuerySet class. Seems like it could get real complex real fast, especially if you're using Q objects. On Mar 22, 4:17 pm, Phlip wrote: > > Just create another queryset that excludes everything in your first > > queryset: > > > n

Re: Negate querysets

2010-03-22 Thread Phlip
> Just create another queryset that excludes everything in your first > queryset: > > negated_queryset = User.objects.exclude(id__in=queryset.values("id")) QuerySets are already so easy to plug-n-play... Ain't there a way to do it without whacking the database twice? -- Phlip http://c2.com/cg

Re: Negate querysets

2010-03-22 Thread Tim Shaffer
Just create another queryset that excludes everything in your first queryset: negated_queryset = User.objects.exclude(id__in=queryset.values("id")) On Mar 22, 3:47 pm, Vinicius Mendes wrote: > Is there any way to negate a queryset? Let's supose i have this queryset: > > User.objects.filter(first

Negate querysets

2010-03-22 Thread Vinicius Mendes
Is there any way to negate a queryset? Let's supose i have this queryset: User.objects.filter(first_name='vinicius') and I want to have the queryset with the objects that is not in first queryset. I know I can do this: User.objects.exclude(first_name='vinicius') But we have cases where we don't