Opened 17 years ago

Closed 16 years ago

#4858 closed (fixed)

Add support for ~ to Q objects for negation

Reported by: Collin Grady <cgrady@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qs-rf-fixed
Cc: elsdoerfer@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

At present there's no quick way to negate a Q object, so if you need something that .filter() and .exclude() can't do, such as Q(A) AND ((NOT Q(B) OR Q(C)), it's a bit awkward as you have to use QNot(Q(B)).

Attached patch would allow Q(A) & (~Q(B) | Q(C)) using the bitwise NOT, similar to the bitwise AND and OR already in use.

Attachments (2)

4858.patch (725 bytes ) - added by Collin Grady <cgrady@…> 17 years ago.
4858.2.patch (2.5 KB ) - added by Collin Grady <cgrady@…> 17 years ago.
added docs and tests

Download all attachments as: .zip

Change History (10)

by Collin Grady <cgrady@…>, 17 years ago

Attachment: 4858.patch added

comment:1 by Collin Grady <cgrady@…>, 17 years ago

Has patch: set

comment:2 by Simon G. <dev@…>, 17 years ago

Summary: Add support for ~ to Q objectsAdd support for ~ to Q objects for negation
Triage Stage: UnreviewedDesign decision needed

Interesting idea, Colin. Can you raise this on django-developers?

by Collin Grady <cgrady@…>, 17 years ago

Attachment: 4858.2.patch added

added docs and tests

comment:3 by miracle2k, 17 years ago

Cc: elsdoerfer@… added

+1 on this.

comment:4 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf added
Triage Stage: Design decision neededAccepted

comment:5 by Fredrik Lundh <fredrik@…>, 17 years ago

Keywords: sprintsept14 added
Triage Stage: AcceptedReady for checkin

comment:6 by Malcolm Tredinnick, 17 years ago

(In [6518]) queryset-refactor: Added ~ support to Q-objects. Based heavily on a patch from
Collin Grady. Refs #4858.

comment:7 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf-fixed added; qs-rf sprintsept14 removed
Triage Stage: Ready for checkinAccepted

Moving back to accepted so it doesn't get checked in on trunk. It's already fixed on the queryset-refactor branch.

comment:8 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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