I'm stuck on this database search problem: I have a PyQt5 widget with different checkBoxes. Each of them represents a column from my database. For example, 'worker_name' and 'department'. checkBoxes are placed near lineEdits, so user inserts some text into this lineEdit, than click on checkBox and 'Find' button.
Let's say, user insert 'John' in lineEdit, than press 'worker_name' checkBox and gets all docs of this worker via
session.query(Doc).filter_by('worker_name'=text_from_lineEdit)
If user insert text in both lineEdits and pressed both checkBoxes ('worker_name' and 'department') query will look like this:
session.query(Doc).filter_by('worker_name'=text_from_lineEdit, 'department'=text_from_lineEdit_2)
But what if I have many checkBoxes (as many as columns in DB table) and i don't know which of them will be pressed and which are not. How should I form the query in that case ? I mean I will have 'wrk_name','department' and 'date' and user could search only by 'worker_name' or by 'worker_name' + 'date' or with all of the checkBoxes.
Is there any way to form database query dynamically relying on which arguments are given and which are not to include them in 'filter_by'/'filter or just ignore.
Please, share your ideas about possible implementation of such functionality. Thx for your time.