Search within search

This search contains all the fields you may want to search:

d1 = datetime.datetime(2022, 8, 20)
d2 = datetime.datetime(2022, 9, 5)
txt = '0'

for row in app_tables.registro.search(
        tables.order_by('fecha'),
        fecha=q.all_of(
            q.greater_than_or_equal_to(d1),
            q.less_than_or_equal_to(d2)
        ),
        placa=q.ilike(f'%{txt}%')
    ):
    print(row['placa'], row['fecha'])

So you can build a dictionary containing one key for each column. Then you build a list containing the two date constraints, then you do something like this, where all the items in the list and in the dictionary are optional:

l = [q.greater_than_or_equal_to(d1), q.less_than_or_equal_to(d2)]
d = {
    'fecha': q.all_of(*l),
    'placa': q.ilike(f'%{txt}%'),
}
for row in app_tables.registro.search(tables.order_by('fecha'), **d):
    print(row['placa'], row['fecha'])
1 Like