add support for ?field__isnull=1 (#107)

* add support for ?field__isnull=1

* Add unit test and conditional formatting for ?field__isnull
This commit is contained in:
Ray N 2017-11-17 08:29:22 -05:00 committed by Simon Willison
commit ed2b3f25be
2 changed files with 17 additions and 3 deletions

View file

@ -46,6 +46,7 @@ def build_where_clauses(args):
'lte': '"{}" <= :{}',
'glob': '"{}" glob :{}',
'like': '"{}" like :{}',
'isnull': '"{}" is null',
}[lookup]
numeric_operators = {'gt', 'gte', 'lt', 'lte'}
value_convert = {
@ -56,11 +57,15 @@ def build_where_clauses(args):
converted = value_convert(value)
if lookup in numeric_operators and converted.isdigit():
converted = int(converted)
param_id = 'p{}'.format(i)
if ':{}' in template:
param_id = 'p{}'.format(i)
params[param_id] = converted
tokens = (column, param_id)
else:
tokens = (column,)
sql_bits.append(
template.format(column, param_id)
template.format(*tokens)
)
params[param_id] = converted
return sql_bits, params