Simplified Contains, StartsWith, and EndsWith lookups.
This commit is contained in:
parent
f0d6f01fbe
commit
8b25d546b6
|
@ -376,6 +376,7 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
|
||||||
|
|
||||||
|
|
||||||
class PatternLookup(BuiltinLookup):
|
class PatternLookup(BuiltinLookup):
|
||||||
|
param_pattern = '%%%s%%'
|
||||||
|
|
||||||
def get_rhs_op(self, connection, rhs):
|
def get_rhs_op(self, connection, rhs):
|
||||||
# Assume we are in startswith. We need to produce SQL like:
|
# Assume we are in startswith. We need to produce SQL like:
|
||||||
|
@ -393,18 +394,18 @@ class PatternLookup(BuiltinLookup):
|
||||||
else:
|
else:
|
||||||
return super().get_rhs_op(connection, rhs)
|
return super().get_rhs_op(connection, rhs)
|
||||||
|
|
||||||
|
def process_rhs(self, qn, connection):
|
||||||
|
rhs, params = super().process_rhs(qn, connection)
|
||||||
|
if params and not self.bilateral_transforms:
|
||||||
|
params[0] = self.param_pattern % connection.ops.prep_for_like_query(params[0])
|
||||||
|
return rhs, params
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class Contains(PatternLookup):
|
class Contains(PatternLookup):
|
||||||
lookup_name = 'contains'
|
lookup_name = 'contains'
|
||||||
prepare_rhs = False
|
prepare_rhs = False
|
||||||
|
|
||||||
def process_rhs(self, qn, connection):
|
|
||||||
rhs, params = super().process_rhs(qn, connection)
|
|
||||||
if params and not self.bilateral_transforms:
|
|
||||||
params[0] = "%%%s%%" % connection.ops.prep_for_like_query(params[0])
|
|
||||||
return rhs, params
|
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class IContains(Contains):
|
class IContains(Contains):
|
||||||
|
@ -415,50 +416,28 @@ class IContains(Contains):
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class StartsWith(PatternLookup):
|
class StartsWith(PatternLookup):
|
||||||
lookup_name = 'startswith'
|
lookup_name = 'startswith'
|
||||||
|
param_pattern = '%s%%'
|
||||||
prepare_rhs = False
|
prepare_rhs = False
|
||||||
|
|
||||||
def process_rhs(self, qn, connection):
|
|
||||||
rhs, params = super().process_rhs(qn, connection)
|
|
||||||
if params and not self.bilateral_transforms:
|
|
||||||
params[0] = "%s%%" % connection.ops.prep_for_like_query(params[0])
|
|
||||||
return rhs, params
|
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class IStartsWith(PatternLookup):
|
class IStartsWith(StartsWith):
|
||||||
lookup_name = 'istartswith'
|
lookup_name = 'istartswith'
|
||||||
prepare_rhs = False
|
prepare_rhs = False
|
||||||
|
|
||||||
def process_rhs(self, qn, connection):
|
|
||||||
rhs, params = super().process_rhs(qn, connection)
|
|
||||||
if params and not self.bilateral_transforms:
|
|
||||||
params[0] = "%s%%" % connection.ops.prep_for_like_query(params[0])
|
|
||||||
return rhs, params
|
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class EndsWith(PatternLookup):
|
class EndsWith(PatternLookup):
|
||||||
lookup_name = 'endswith'
|
lookup_name = 'endswith'
|
||||||
|
param_pattern = '%%%s'
|
||||||
prepare_rhs = False
|
prepare_rhs = False
|
||||||
|
|
||||||
def process_rhs(self, qn, connection):
|
|
||||||
rhs, params = super().process_rhs(qn, connection)
|
|
||||||
if params and not self.bilateral_transforms:
|
|
||||||
params[0] = "%%%s" % connection.ops.prep_for_like_query(params[0])
|
|
||||||
return rhs, params
|
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class IEndsWith(PatternLookup):
|
class IEndsWith(EndsWith):
|
||||||
lookup_name = 'iendswith'
|
lookup_name = 'iendswith'
|
||||||
prepare_rhs = False
|
prepare_rhs = False
|
||||||
|
|
||||||
def process_rhs(self, qn, connection):
|
|
||||||
rhs, params = super().process_rhs(qn, connection)
|
|
||||||
if params and not self.bilateral_transforms:
|
|
||||||
params[0] = "%%%s" % connection.ops.prep_for_like_query(params[0])
|
|
||||||
return rhs, params
|
|
||||||
|
|
||||||
|
|
||||||
@Field.register_lookup
|
@Field.register_lookup
|
||||||
class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
|
class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
|
||||||
|
|
Loading…
Reference in New Issue