diff options
| author | David Sanders <> | 2024-04-21 16:46:26 +1000 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-05-02 21:45:02 -0300 |
| commit | fa202d5cb1f16b9bbfd9da72eb03125fabc34bb8 (patch) | |
| tree | 9de51569304470b30f0e841641b159e1cc0f2051 /django | |
| parent | f29922b6ef10e913a12d569eec0a87d3ae208235 (diff) | |
[5.0.x] Refs #34007, Refs #35359 -- Added Q.referenced_based_fields property.
Thank you to Mariusz Felisiak and Natalia Bidart for the reviews.
Backport of 97d48cd3c6f409584b5cc19fbddfca917bae78fd from main
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query_utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index e1041b9653..a04bbad5e7 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: """ |
