mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Made Extracts aware of full lookup path
This commit is contained in:
parent
27a57b7aed
commit
ed8fab7fe8
@ -6,8 +6,9 @@ from django.utils.functional import cached_property
|
|||||||
|
|
||||||
|
|
||||||
class Extract(object):
|
class Extract(object):
|
||||||
def __init__(self, lhs):
|
def __init__(self, lhs, lookups):
|
||||||
self.lhs = lhs
|
self.lhs = lhs
|
||||||
|
self.init_lookups = lookups[:]
|
||||||
|
|
||||||
def get_lookup(self, lookup):
|
def get_lookup(self, lookup):
|
||||||
return self.output_type.get_lookup(lookup)
|
return self.output_type.get_lookup(lookup)
|
||||||
|
@ -1082,26 +1082,27 @@ class Query(object):
|
|||||||
|
|
||||||
def build_lookup(self, lookups, lhs, rhs):
|
def build_lookup(self, lookups, lhs, rhs):
|
||||||
lookups = lookups[:]
|
lookups = lookups[:]
|
||||||
lookups.reverse()
|
|
||||||
while lookups:
|
while lookups:
|
||||||
lookup = lookups.pop()
|
lookup = lookups[0]
|
||||||
next = lhs.get_lookup(lookup)
|
next = lhs.get_lookup(lookup)
|
||||||
if next:
|
if next:
|
||||||
if not lookups:
|
if len(lookups) == 1:
|
||||||
# This was the last lookup, so return value lookup.
|
# This was the last lookup, so return value lookup.
|
||||||
if issubclass(next, Extract):
|
if issubclass(next, Extract):
|
||||||
lhs = next(lhs)
|
lookups.append('exact')
|
||||||
next = lhs.get_lookup('exact')
|
lhs = next(lhs, lookups)
|
||||||
|
else:
|
||||||
return next(lhs, rhs)
|
return next(lhs, rhs)
|
||||||
else:
|
else:
|
||||||
lhs = next(lhs)
|
lhs = next(lhs, lookups)
|
||||||
# A field's get_lookup() can return None to opt for backwards
|
# A field's get_lookup() can return None to opt for backwards
|
||||||
# compatibility path.
|
# compatibility path.
|
||||||
elif len(lookups) > 1:
|
elif len(lookups) > 2:
|
||||||
raise FieldError(
|
raise FieldError(
|
||||||
"Unsupported lookup for field '%s'" % lhs.output_type.name)
|
"Unsupported lookup for field '%s'" % lhs.output_type.name)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
lookups = lookups[1:]
|
||||||
|
|
||||||
def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
|
def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
|
||||||
can_reuse=None, connector=AND):
|
can_reuse=None, connector=AND):
|
||||||
|
Loading…
Reference in New Issue
Block a user