On Dec 13, 5:18 pm, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Is there a way to express != in a database query?
>
<snip>
> or mayby
> filter(s1=1, !Q(s2=1))
> but I don't see any way to do this in the docs. Hopefully I am just
> overlooking something!
There is an undocumented class called QNot which resides in
django.db.models.query. It takes a Q object as a parameter. Using QNot
your example would look like this:
Foo.objects.filter(Q(s1=1) | QNot(Q(s2=1))
The sql produced looks like:
... WHERE (("s1" = 1 OR (NOT ("s2" = 1))))
I'm not sure if this is exactly the same as 's2 <> 1', though. Any
ideas?
Regards,
Jan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---