Doing query with 'ne' terms.

2007-06-14 Thread Nicholas Ding
I found Django can not do '<>' operation in SQL, such as "where column <> %s". While diving into the source code, it seems easy to add a 'ne' to existing query terms. But why Django doesn't include this, it's confuse me a lot. Best Regards. -- Nicholas @ Nirvana Studio http://www.nirvanastudio.or

Re: Doing query with 'ne' terms.

2007-06-14 Thread Todd O'Bryan
Django uses different functions for this. To get the opposite of this (the ne version) Foo.objects.filter(bar__exact='something') do Foo.objects.exclude(bar__exact='something') HTH, Todd On Fri, 2007-06-15 at 11:37 +0800, Nicholas Ding wrote: > I found Django can not do '<>' operation in SQL,

Re: Doing query with 'ne' terms.

2007-06-14 Thread Nicholas Ding
but I wanna 'where column1 <> %s and column2 <> %s' If I were using exclude, the SQL must be 'where not (column1 = %s and column2 = %s), that's different. On 6/15/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote: > > > Django uses different functions for this. To get the opposite of this > (the ne versi

Re: Doing query with 'ne' terms.

2007-06-14 Thread Todd O'Bryan
You can do a custom SQL query. I don't think you'd *have* to for this, but someone else will have to provide the correct translation. Todd On Fri, 2007-06-15 at 11:50 +0800, Nicholas Ding wrote: > but I wanna 'where column1 <> %s and column2 <> %s' > If I were using exclude, the SQL must be 'whe

Re: Doing query with 'ne' terms.

2007-06-14 Thread SmileyChris
On Jun 15, 3:50 pm, "Nicholas Ding" <[EMAIL PROTECTED]> wrote: > but I wanna 'where column1 <> %s and column2 <> %s' > If I were using exclude, the SQL must be 'where not (column1 = %s and > column2 = %s), that's different. I think you want: objects.exclude(column1=test1).exclude(column2=test2)

Re: Doing query with 'ne' terms.

2007-06-14 Thread Nick
On Jun 15, 12:50 pm, "Nicholas Ding" <[EMAIL PROTECTED]> wrote: > but I wanna 'where column1 <> %s and column2 <> %s' > If I were using exclude, the SQL must be 'where not (column1 = %s and > column2 = %s), that's different. http://www.djangoproject.com/documentation/db-api/#complex-lookups-with-

Re: Doing query with 'ne' terms.

2007-06-14 Thread Nicholas Ding
It works! But why not add a 'ne' term to do this? eg. Foo.objects.filter(column1__ne='', column2__ne='') I think it's more simple. Thanks. On 6/15/07, Nick <[EMAIL PROTECTED]> wrote: > > > On Jun 15, 12:50 pm, "Nicholas Ding" <[EMAIL PROTECTED]> wrote: > > but I wanna 'where column1 <> %s and col

Re: Doing query with 'ne' terms.

2007-06-14 Thread James Bennett
On 6/15/07, Nicholas Ding <[EMAIL PROTECTED]> wrote: > But why not add a 'ne' term to do this? > eg. Foo.objects.filter(column1__ne='', column2__ne='') > I think it's more simple. Older versions of Django supported that, but the current 'exclude' syntax is a little more robust in terms of things