Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#6065 closed (invalid)

Field Lookup - notin

Reported by: RichardH <Richard.House@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: NOT IN
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Field Lookups include IN which is the SQL equivalent of:

SELECT ... WHERE id IN (1, 3, 4);

The docs example is:

Entry.objects.filter(id__in=[1, 3, 4])

However, there is no Field lookup for the SQL equivalent of:

SELECT ... WHERE id NOT IN (1, 3, 4);

The attached patch implements NOTIN shown in the example:

Entry.objects.filter(id__notin=[1, 3, 4])

It works on sqlite, but I haven't tested it extensively. Someone with more than my limited understanding of the db code needs to look for possible implications.

Attachments (1)

sql_notin.patch (1.7 KB) - added by RichardH <Richard.House@…> 9 years ago.
Patch for implementing NOTIN

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by RichardH <Richard.House@…>

Attachment: sql_notin.patch added

Patch for implementing NOTIN

comment:1 Changed 9 years ago by James Bennett

Resolution: invalid
Status: newclosed

This is what exclude() is for; otherwise every database lookup operator would need a corresponding "not" version.

comment:2 Changed 9 years ago by RichardH <Richard.House@…>

Thanks. The pointer to exclude()has provided me with enlightenment :)
Richard

Note: See TracTickets for help on using tickets.
Back to Top