Opened 8 years ago

Closed 7 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: master
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: UI/UX:

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@…> 8 years ago.
4858.2.patch (2.5 KB) - added by Collin Grady <cgrady@…> 8 years ago.
added docs and tests

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by Collin Grady <cgrady@…>

comment:1 Changed 8 years ago by Collin Grady <cgrady@…>

  • Has patch set

comment:2 Changed 8 years ago by Simon G. <dev@…>

  • Summary changed from Add support for ~ to Q objects to Add support for ~ to Q objects for negation
  • Triage Stage changed from Unreviewed to Design decision needed

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

Changed 8 years ago by Collin Grady <cgrady@…>

added docs and tests

comment:3 Changed 8 years ago by miracle2k

  • Cc elsdoerfer@… added

+1 on this.

comment:4 Changed 7 years ago by mtredinnick

  • Keywords qs-rf added
  • Triage Stage changed from Design decision needed to Accepted

comment:5 Changed 7 years ago by Fredrik Lundh <fredrik@…>

  • Keywords sprintsept14 added
  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 7 years ago by mtredinnick

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

comment:7 Changed 7 years ago by mtredinnick

  • Keywords qs-rf-fixed added; qs-rf sprintsept14 removed
  • Triage Stage changed from Ready for checkin to Accepted

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

comment:8 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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