summaryrefslogtreecommitdiff
path: root/django/db/models/query_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/query_utils.py')
-rw-r--r--django/db/models/query_utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 9be17a4a84..1bf396723e 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -175,6 +175,19 @@ class Q(tree.Node):
def __hash__(self):
return hash(self.identity)
+ @cached_property
+ def referenced_base_fields(self):
+ """
+ Retrieve all base fields referenced directly or through F expressions
+ excluding any fields referenced through joins.
+ """
+ # Avoid circular imports.
+ from django.db.models.sql import query
+
+ return {
+ child.split(LOOKUP_SEP, 1)[0] for child in query.get_children_from_q(self)
+ }
+
class DeferredAttribute:
"""