You could have a series of drop-down lists containing field names. Each drop-down list could be separated from the next by a pair of fixed-choice buttons setting "OR" or "AND" between the lists. Where it gets tricky is that you may want the user to be able to use brackets around some of their selections.
Does someone know if their are "plugins" for Django to get a type of filtering on the models like the "advanced" filter options on the Bitbucket issues page or even "more advanced" like pubmed? This last one can also do the "bracket-option". I would think this is a quite common feature needed, but I can't find anything. It might be I'm searching with the wrong terms.
First attempt implementing complex filtering by a query builder form using Django Q objects:
- For now only fields in CT models are selectable (DX/RF/Mammo-fields are not added, but could easily)
- AND / OR / AND NOT / OR NOT can be chosen to connect constraints on fields
- Brackets can be used (first and last textbox, this might be unclear for the user)
- For now the search is completely modality independent, although results use CT template and only CT models are loaded
- For now page is only reachable by manually entering http://server:port/openrem/advanced_search
Things that need to be done (at least):
- Check for validity of user input
* only decimals in decimal fields, dates in date fields, etc..
* Correct placing of brackets
- Results for queries without brackets are almost certainly correct, but with brackets need to be tested thoroughly
- If query is sent, the results page should also contain the query as built by the user (textboxes should be filled). So the user can adapt the query easily
- Think about available fields...There are a lot. Do we need to sort or limit them?
- Verbose name is used for displaying field names, but we may need to add these to the model for a number of fields for clarity
- Should it be possible to select "NOT" for the first field search?
- Pressing <Enter> while "add line" is selected will add extra line, but selected "add line" icon remains visible and next line added is empty
- Write test script
I just committed a first attempt for making complex filtering possible (advanced search).
It isn't finished by far, but I'm really curious what you (@Ed McDonagh, @David Platten, @Tim de Wit) think about the principal and possibilities.
See commit 638fb3e, for some additional remarks