Fixed #21863 -- supplemented get_lookup() with get_transform()

Also fixed #22124 -- Expanded explanation of exactly what is going on in
as_sql() methods.
This commit is contained in:
Anssi Kääriäinen 2014-03-01 21:21:57 +02:00 committed by Marc Tamlyn
parent a0f2525202
commit 219d928852
6 changed files with 177 additions and 41 deletions

View file

@ -1088,24 +1088,21 @@ class Query(object):
lookups = lookups[:]
while lookups:
lookup = lookups[0]
next = lhs.get_lookup(lookup)
if len(lookups) == 1:
final_lookup = lhs.get_lookup(lookup)
if final_lookup:
return final_lookup(lhs, rhs)
# We didn't find a lookup, so we are going to try get_transform
# + get_lookup('exact').
lookups.append('exact')
next = lhs.get_transform(lookup)
if next:
if len(lookups) == 1:
# This was the last lookup, so return value lookup.
if issubclass(next, Transform):
lookups.append('exact')
lhs = next(lhs, lookups)
else:
return next(lhs, rhs)
else:
lhs = next(lhs, lookups)
# A field's get_lookup() can return None to opt for backwards
# compatibility path.
elif len(lookups) > 2:
raise FieldError(
"Unsupported lookup for field '%s'" % lhs.output_type.name)
lhs = next(lhs, lookups)
else:
return None
raise FieldError(
"Unsupported lookup '%s' for %s or join on the field not "
"permitted." %
(lookup, lhs.output_type.__class__.__name__))
lookups = lookups[1:]
def build_filter(self, filter_expr, branch_negated=False, current_negated=False,