I’m displaying a page with a 4 textboxes, each storing the user entered value into a separate variable.
My Database has 4 columns, each corresponding to one text box’s variable.
I want to do this:
The user can enter values in 1,2,3 or all 4 of the textboxes, and I want to trim the search results according to each value that they’ve entered. Each textbox is optional.
How do I do this? I’m new at Django, and I only know how to search using one search term.
I think you need Q objects. See: https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects
From the docs:
Translates to:
You can populate the Q query from your cleaned form – you might even want to override clean() and return the queryset that way, so that you could just access the query set from the validated form.