mirror of
https://github.com/django/django.git
synced 2025-08-08 04:48:27 +00:00
Refs #24267 -- Implemented lookups for related fields
Previously related fields didn't implement get_lookup, instead related fields were treated specially. This commit removed some of the special handling. In particular, related fields return Lookup instances now, too. Other notable changes in this commit is removal of support for annotations in names_to_path().
This commit is contained in:
parent
8654c6a732
commit
b68212f539
6 changed files with 219 additions and 94 deletions
|
@ -250,7 +250,7 @@ deferred_class_factory.__safe_for_unpickling__ = True
|
|||
|
||||
def refs_aggregate(lookup_parts, aggregates):
|
||||
"""
|
||||
A little helper method to check if the lookup_parts contains references
|
||||
A helper method to check if the lookup_parts contains references
|
||||
to the given aggregates set. Because the LOOKUP_SEP is contained in the
|
||||
default annotation names we must check each prefix of the lookup_parts
|
||||
for a match.
|
||||
|
@ -260,3 +260,17 @@ def refs_aggregate(lookup_parts, aggregates):
|
|||
if level_n_lookup in aggregates and aggregates[level_n_lookup].contains_aggregate:
|
||||
return aggregates[level_n_lookup], lookup_parts[n:]
|
||||
return False, ()
|
||||
|
||||
|
||||
def refs_expression(lookup_parts, annotations):
|
||||
"""
|
||||
A helper method to check if the lookup_parts contains references
|
||||
to the given annotations set. Because the LOOKUP_SEP is contained in the
|
||||
default annotation names we must check each prefix of the lookup_parts
|
||||
for a match.
|
||||
"""
|
||||
for n in range(len(lookup_parts) + 1):
|
||||
level_n_lookup = LOOKUP_SEP.join(lookup_parts[0:n])
|
||||
if level_n_lookup in annotations and annotations[level_n_lookup]:
|
||||
return annotations[level_n_lookup], lookup_parts[n:]
|
||||
return False, ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue