summaryrefslogtreecommitdiff
path: root/django/db/models/query_utils.py
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2016-11-06 10:37:07 +0000
committerTim Graham <timograham@gmail.com>2017-02-23 20:47:48 -0500
commit508b5debfb16843a8443ebac82c1fb91f15da687 (patch)
tree1281cdc5b664d118bf709686c49fc3ceae42dd4c /django/db/models/query_utils.py
parent19b2dfd1bfe7fd716dd3d8bfa5f972070d83b42f (diff)
downloaddjango-508b5debfb16843a8443ebac82c1fb91f15da687.tar.gz
Refs #11964 -- Made Q objects deconstructible.
Diffstat (limited to 'django/db/models/query_utils.py')
-rw-r--r--django/db/models/query_utils.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 7b1c46f15c..fe1d8f9f69 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -56,7 +56,9 @@ class Q(tree.Node):
default = AND
def __init__(self, *args, **kwargs):
- super().__init__(children=list(args) + list(kwargs.items()))
+ connector = kwargs.pop('_connector', None)
+ negated = kwargs.pop('_negated', False)
+ super().__init__(children=list(args) + list(kwargs.items()), connector=connector, negated=negated)
def _combine(self, other, conn):
if not isinstance(other, Q):
@@ -86,6 +88,19 @@ class Q(tree.Node):
query.promote_joins(joins)
return clause
+ def deconstruct(self):
+ path = '%s.%s' % (self.__class__.__module__, self.__class__.__name__)
+ args, kwargs = (), {}
+ if len(self.children) == 1 and not isinstance(self.children[0], Q):
+ child = self.children[0]
+ kwargs = {child[0]: child[1]}
+ else:
+ args = tuple(self.children)
+ kwargs = {'_connector': self.connector}
+ if self.negated:
+ kwargs['_negated'] = True
+ return path, args, kwargs
+
class DeferredAttribute:
"""