mirror of
https://github.com/django/django.git
synced 2025-10-29 00:26:07 +00:00
Fixed #29865 -- Added logical XOR support for Q() and querysets.
This commit is contained in:
committed by
Mariusz Felisiak
parent
795da6306a
commit
c6b4d62fa2
@@ -396,6 +396,25 @@ class QuerySet:
|
||||
combined.query.combine(other.query, sql.OR)
|
||||
return combined
|
||||
|
||||
def __xor__(self, other):
|
||||
self._check_operator_queryset(other, "^")
|
||||
self._merge_sanity_check(other)
|
||||
if isinstance(self, EmptyQuerySet):
|
||||
return other
|
||||
if isinstance(other, EmptyQuerySet):
|
||||
return self
|
||||
query = (
|
||||
self
|
||||
if self.query.can_filter()
|
||||
else self.model._base_manager.filter(pk__in=self.values("pk"))
|
||||
)
|
||||
combined = query._chain()
|
||||
combined._merge_known_related_objects(other)
|
||||
if not other.query.can_filter():
|
||||
other = other.model._base_manager.filter(pk__in=other.values("pk"))
|
||||
combined.query.combine(other.query, sql.XOR)
|
||||
return combined
|
||||
|
||||
####################################
|
||||
# METHODS THAT DO DATABASE QUERIES #
|
||||
####################################
|
||||
|
||||
Reference in New Issue
Block a user