template drop down menu

19 views
Skip to first unread message

sum abiut

unread,
Jun 6, 2017, 1:41:03 AM6/6/17
to django...@googlegroups.com
Hi,
need some directions, i need to query the my database and display the result of the query in the table. to do that i want to use a drop down menu and get the users to select options from the drop menu on the template.

for example if a user select a word from the drop down menu i want to filter and query the database base on the option that is selected and then display the result.

I am confuse on the template side. on the template side how to i know if a user select a particular option from the drop down before so that i can perform query base on option that was selected from the template and display query result base on the respective word that was select.

Cheers,

ludovic coues

unread,
Jun 6, 2017, 2:06:37 PM6/6/17
to django...@googlegroups.com
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

sum abiut

unread,
Jun 6, 2017, 4:59:04 PM6/6/17
to django...@googlegroups.com
Thanks heaps for your response. It really clear things up and help me get started.

Cheers,






--

Cordialement, Ludovic Coues
+33 6 14 87 43 42

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Bernd Wechner

unread,
Jun 6, 2017, 6:23:08 PM6/6/17
to django...@googlegroups.com
If you want a sample for a javascript postback when drop down changes I have one here:

https://github.com/bernd-wechner/CoGs/blob/master/Leaderboards/templates/CoGs/view_leaderboards.html

It's attached to the select "selNames" which you can trace to the Django view "ajax_Leaderboards" in:

https://github.com/bernd-wechner/CoGs/blob/master/Leaderboards/views.py

if you're patient.

Might be easier to find some simple tutorials than wade through my code, but hey, it's there to look at if you want to see a working demo (almost, that site isn't live yet so can't point you at it running alas).

Regards,

Bernd.

sum abiut wrote:
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.

sum abiut

unread,
Jun 6, 2017, 7:18:19 PM6/6/17
to django...@googlegroups.com
Thanks heaps for your response. I will have a look into it.

Cheers,

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

Reply all
Reply to author
Forward
0 new messages