Autocompletion is obtained throught autocomplete_light package.
A patch is applied to the js code of the widget to add the capability of filtering in a dynamic way, i.e. passing to the function also the id of other elements in the page that have already being selected.
This module provides DynamicAutocompleteModelBase a class that inherits from autocomplete_light.AutocompleteModelBase.
You can define a dictionary called filters whose keys are queryset filter keywords and whose values are dom id. The js widget will retrieve the values of the ids and send them along with the string used in the autocompletion:
from jmb.core.utils.autocomplete import DynamicAutocompleteModelBase
class MyAutocomplete(DynamicAutocompleteModelBase):
filters = {
'organization_id' : '#id_organization',
'project_id' : '#id_project',
}
In this situation the widget will call the url:
/ticket/autocomplete/MyAutocomplete/?q=san&organization_id=1530&project_id=10
that will be handled automatically by choices_for_request
Return all choices taking into account all dynamic filters
you may need to customize this
a dict. Keys must be keywords to filter a quesryset, e.g.: organization_id, organization__address__country_id, and the values must be id in the html page whose value will be retrieved by javascript and sent along (e.g.: #organization_id)