Let’s say I have a data table with many products. Some of these products have a discontinued date and some of them do not.
So the products table looks like:
name | discontinued_date
product_1 | None
product_2 | None
product_3 | 2020-04-19
product_4 | None
I am trying to query the products data table with three different queries. Either “All”, “Not Discontinued”, or “Discontinued”. They should return:
“All”: products 1, 2, 3, and 4
“Not Discontinued”: products 1, 2, and 4
“Discontinued”: product 3
My thinking was to create a drop down in the UI with these three options. Then I could do something like:
if self.drop_down.selected_value == 'All':
query_discontinued = # ... a query that does not filter anything
elif self.drop_down.selected_value == 'Not Discontinued':
query_discontinued = # ... a query to get all None values
elif self.drop_down.selected_value == 'Discontinued':
query_discontinued = # ... a query to get all not None values
My intention was then to pass this to the server side to do a search with something like
@anvil.server.callable
def get_products(query_discontinued):
return app_tables.products.search(date_discontinued = query_discontinued)
It feels like there is a simple and proper way to do this. I have so far only done ways that I felt were hackish. So my question is what would be the three queries that I could write in the if statements?
Follow up question: Is there an overall better way to do this entire process?