summaryrefslogtreecommitdiff
path: root/django/db/models/query_utils.py
diff options
context:
space:
mode:
authorDavid Sanders <>2024-04-21 16:46:26 +1000
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-05-02 19:05:13 +0200
commit97d48cd3c6f409584b5cc19fbddfca917bae78fd (patch)
tree9daa51c1a9914b6ee81d213826bbd52b338d12a0 /django/db/models/query_utils.py
parent39828fa7786a805f7a542abb929f352d3c5b722c (diff)
Refs #34007, Refs #35359 -- Added Q.referenced_based_fields property.
Thank you to Mariusz Felisiak and Natalia Bidart for the reviews.
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:
"""