Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example to have Not Equal operator? #87

Open
simkimsia opened this issue Jun 23, 2017 · 2 comments
Open

An example to have Not Equal operator? #87

simkimsia opened this issue Jun 23, 2017 · 2 comments

Comments

@simkimsia
Copy link

Hi there,

I know that Django QuerySet typically favors exclude to cater for not equal queries

I wonder how django query builder handles not equal operator?

@firemark
Copy link

Maybe ~Q(value=wrong_val)?

@somewes
Copy link
Contributor

somewes commented Feb 19, 2018

@simkimsia
The where method accepts a Q object, which can be negated with a ~ as @firemark suggested. It would be nice to have a "not equals" operator to do things like .where(field__not='value') so I'll leave this ticket open as a reminder and update the docs with examples.

In [19]: from django.db.models import Q

In [20]: q = Query().from_table(Account).where(~Q(first_name='Test'))

In [21]: q.get_sql()
Out[21]: 'SELECT account_account.* FROM account_account WHERE ((NOT(first_name = %(A0)s)))'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants