What I’m trying to do:
I have a search by date in a repeating panel of a list of vehicles that works well, but I was given the requirement that I also have to be able to search a car by plate number within the dates given, how should I add the plate number search has an optional parameter, I mean if i do not give a plate number it will still show me the vehicles in the time range, and if I give the plate it will show only the vehicle with the plane number within the dates given
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
start_date = self.date_picker_2.date
end_date = self.date_picker_3.date
queries = [q.none_of()]
if start_date:
queries.append(q.any_of(fecha=q.greater_than_or_equal_to(start_date)))
if end_date:
queries.append(q.any_of(fecha=q.less_than_or_equal_to(end_date)))
self.repeating_panel_busqueda_fecha.items = app_tables.registro.search(q.all_of(*queries))
pass
Clone link:
share a copy of your app
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
to present it on the repeating panel “self.repeating_panel_busqueda_fecha.items” should i use the same method or what should i do?
Something like this should work:
rows = app_tables.registro.search([...])
self.repeating_panel_busqueda_fecha.items = rows
This is a different question from the previous one, and doesn’t match the subject.
Please create a new post when you have a new question, so you have higher chances to get an answer and it will be useful to new comers in the future.
1 Like