mirror of
https://github.com/django/django.git
synced 2025-08-23 12:04:21 +00:00
Fixed #29865 -- Added logical XOR support for Q() and querysets.
This commit is contained in:
parent
795da6306a
commit
c6b4d62fa2
19 changed files with 311 additions and 18 deletions
|
@ -94,7 +94,7 @@ class Combinable:
|
|||
if getattr(self, "conditional", False) and getattr(other, "conditional", False):
|
||||
return Q(self) & Q(other)
|
||||
raise NotImplementedError(
|
||||
"Use .bitand() and .bitor() for bitwise logical operations."
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
def bitand(self, other):
|
||||
|
@ -106,6 +106,13 @@ class Combinable:
|
|||
def bitrightshift(self, other):
|
||||
return self._combine(other, self.BITRIGHTSHIFT, False)
|
||||
|
||||
def __xor__(self, other):
|
||||
if getattr(self, "conditional", False) and getattr(other, "conditional", False):
|
||||
return Q(self) ^ Q(other)
|
||||
raise NotImplementedError(
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
def bitxor(self, other):
|
||||
return self._combine(other, self.BITXOR, False)
|
||||
|
||||
|
@ -113,7 +120,7 @@ class Combinable:
|
|||
if getattr(self, "conditional", False) and getattr(other, "conditional", False):
|
||||
return Q(self) | Q(other)
|
||||
raise NotImplementedError(
|
||||
"Use .bitand() and .bitor() for bitwise logical operations."
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
def bitor(self, other):
|
||||
|
@ -139,12 +146,17 @@ class Combinable:
|
|||
|
||||
def __rand__(self, other):
|
||||
raise NotImplementedError(
|
||||
"Use .bitand() and .bitor() for bitwise logical operations."
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
def __ror__(self, other):
|
||||
raise NotImplementedError(
|
||||
"Use .bitand() and .bitor() for bitwise logical operations."
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
def __rxor__(self, other):
|
||||
raise NotImplementedError(
|
||||
"Use .bitand(), .bitor(), and .bitxor() for bitwise logical operations."
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue