from django.db.models import Q


class QQ:

    def __xor__(self, other):
        not_self = self.clone()
not_other = other.clone()
not_self.negate()
not_other.negate()
x = self & not_other
y = not_self & other
return x | y
Q.__bases__ += QQ,
Perform a logical exclusive OR on a Django Q object