This is a semi-long question. Please let me know wherever I make a mistake.
I'm building a search form with 4 required choices, 1 of the choices is a CharField with a max_length of 3. The other 3 choices are ChoiceField's. Here is a picture of what the search form looks like:
I've read through the Django docs and other things on the Internet but I'm still very unclear about how to approach this.
1. First I believe I need to create 4 args or kwargs in the url for each of the choices. If I use args, it would look something like...
url(r'^search?(\w+{3})&(\w+{2})&(\w+{1-2})&(\w+{1-2})', function/class view, name='search')
2. Next, I need to pass the user's input in the html page into the url args. I have a form set up to get the user's input. But how would I write this on the HTML page? Do I simply make a url tag like {% url 'search' args1, args2, args3, args4 %}?
3. Then I need to create the views function. My first question is, should I use a function-based view or the generic class-based ListView? The result of the search will be a list of items, so ListView is a good template to use, but I don't know how having 4 args would affect using ListView. My second question is, what is the most effective way of making this search? I need to check if any records in the database matches the user's search, so would I do something like 'For record in database' to check over every record in the database?
If I used a function view, would it look something like:
def search(request, args1, args2, args3, args4):