On Thu, Apr 16, 2009 at 3:56 PM, Thomas Guettler <h...@tbz-pariv.de> wrote:
>
> Hi,
>
>
> For forms which display a list of results I use:
>    form=QueryForm(request.GET)
>    ....
>    queryset=MyModel.objects.filter(**form.cleaned_data)
>
> But, now I need to use exclude() instead of filter().
>
> I looked at the queryset API, but it seems that there is no
> alternative to qs.exclude().
>
> Wouldn't it be nice to have a "not" field lookup? Example:
>
> MyModel.objects.filter(field__not=...)
> MyModel.objects.filter(field__not__in=...)
>


There is this:

from django.db.models import Q
MyModel.objects.filter(~Q(field__in=...))

This should do what you want. You could also let the form create an
appropriate Q object which you can pass into the filter method.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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