mirror of
https://github.com/django/django.git
synced 2025-11-30 07:19:08 +00:00
Refs #32946 -- Changed Query.add_filter() to take two arguments.
This commit is contained in:
parent
5fee36973c
commit
5b8ef8aa5b
4 changed files with 22 additions and 17 deletions
|
|
@ -1357,8 +1357,8 @@ class Query(BaseExpression):
|
|||
clause.add(lookup_class(value, False), AND)
|
||||
return clause, used_joins if not require_outer else ()
|
||||
|
||||
def add_filter(self, filter_clause):
|
||||
self.add_q(Q(**{filter_clause[0]: filter_clause[1]}))
|
||||
def add_filter(self, filter_lhs, filter_rhs):
|
||||
self.add_q(Q((filter_lhs, filter_rhs)))
|
||||
|
||||
def add_q(self, q_object):
|
||||
"""
|
||||
|
|
@ -1762,15 +1762,15 @@ class Query(BaseExpression):
|
|||
LIMIT 1
|
||||
)
|
||||
"""
|
||||
filter_lhs, filter_rhs = filter_expr
|
||||
if isinstance(filter_rhs, OuterRef):
|
||||
filter_expr = (filter_lhs, OuterRef(filter_rhs))
|
||||
elif isinstance(filter_rhs, F):
|
||||
filter_expr = (filter_lhs, OuterRef(filter_rhs.name))
|
||||
# Generate the inner query.
|
||||
query = Query(self.model)
|
||||
query._filtered_relations = self._filtered_relations
|
||||
query.add_filter(filter_expr)
|
||||
filter_lhs, filter_rhs = filter_expr
|
||||
if isinstance(filter_rhs, OuterRef):
|
||||
filter_rhs = OuterRef(filter_rhs)
|
||||
elif isinstance(filter_rhs, F):
|
||||
filter_rhs = OuterRef(filter_rhs.name)
|
||||
query.add_filter(filter_lhs, filter_rhs)
|
||||
query.clear_ordering(force=True)
|
||||
# Try to have as simple as possible subquery -> trim leading joins from
|
||||
# the subquery.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue