The short answer to "how can I know what option is selected before
doing the queyr" is "you cannot know".
Here is a quick drawing of your timeline
request to your server -> process view (where you do db request) ->
process template -> send request back to user -> user select an option
At no point you can go backward in this schema. The trick is to do it again.
The easy solution is to put the select in a form with a submit button
named "search" or "filter". The first time you show the page, you
display an empty or full list. When your user submit the form, you
know which option they have selected.
If you involve javascript, you can make it as complex as you want.
First solution is to force a form submission as soon as the value of
the select change. Next solution is to not reload the whole page but
do an ajax call. That ajax request can either return the whole list as
a fragment of HTML to replace the previous list or some formatted
data, as JSON for example that you can use to replace the data in the
list. Last solution would be to not use the server for the filtering.
Send everything to the user and use javascript to filter the data
according to the value of the select. With no request to your server,
data will be updated really fast. That solution work really well for
small to medium amount of data.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
django-users...@googlegroups.com.
> To post to this group, send email to
django...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/django-users.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/CAPCf-y5ZZdhwV-D71SVQ-50dQDFbhNP7KtBZMR0x7NiBVVQh9A%40mail.gmail.com.
> For more options, visit
https://groups.google.com/d/optout.
--
Cordialement, Ludovic Coues
+33 6 14 87 43 42