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 <vbmen...@gmail.com> wrote:
> 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 know what is the queryset, we only knows
> that we want to get the elements that isn't in it, like this:
>
> queryset.negate()
>
> It's good to keep the chainable property of querysets.
>
> ______________________
> Vinícius Mendes
> Solucione Sistemashttp://solucione.info/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to