Templating autocompletes

This documentation drives through the example app template_autocomplete, which is available in test_project.

API

In autocomplete_light/autocomplete/__init__.py, it is used as a mixin:

class AutocompleteModelBase(AutocompleteModel, AutocompleteBase):
    pass


class AutocompleteModelTemplate(AutocompleteModel, AutocompleteTemplate):
    pass

Example

In this case, all you have to do, is use AutocompleteModelTemplate instead of AutocompleteModelBase. For example, in test_project/template_autocomplete/autocomplete_light_registry.py:

import autocomplete_light

from models import TemplatedChoice

autocomplete_light.register(TemplatedChoice, 
	autocomplete_light.AutocompleteModelTemplate, 
	choice_template='template_autocomplete/templated_choice.html')

This example template makes choices clickable, it is test_project/template_autocomplete/templates/template_autocomplete/templated_choice.html:

<div data-value="{{ choice.pk }}">
	<a href="{% url admin:template_autocomplete_templatedchoice_change choice.pk %}?_popup=1" target="_blank">
		{{ choice }}
	</a>
</div>