[Django]-How to create a dependant drop down using autocomplete light

2👍

The self.request.POST (or self.request.GET) QueryDict of an Autocomplete class will not contain any more information than the search query because they are not passed when the view is created (so self.request.POST.get('category', 'none') will always return 'none').

So the difficult part is to somehow pass an argument (category) to a completely different view. This could be done, for instance by modifying the javascript that calls the autocomplete. Meaning, you’ll need to change getQuery (http://django-autocomplete-light.readthedocs.org/en/stable-2.x.x/script.html#override-autocomplete-js-methods) to append category=foo to the url that is called and then, at choices_for_request read the self.request.GET QueryDictto get that value.

Another way to do it is to put the category parameter to your session and then read the session in the choices_for_request. For example, on the __init__ of your view you’ll do something like self.request.session['category'] = 'foo' and on the choices_for_request you’ll get that value.

Leave a comment