Typeahead inputs built on top of Django and Bootstrap.
> pip install django-bootstrap-typeahead
- Add
django_bootstrap_typeahead
to the installed apps of your Django Project - create a form and use
TypeaheadField
instead ofModelChoiceField
orMultipleTypeaheadField
instead ofModelMultipleChoiceField
- Be sure to include the form's required media in the template. ie.
{{ form.media }}
- Also be sure to include Twitter Bootstrap
forms.py
from django import forms
from django_bootstrap_typeahead.fields import *
from .models import Thing
def build_thing(value):
thing, created = Thing.objects.get_or_create(name=value)
return thing
class TestForm(forms.Form):
typeahead = TypeaheadField(
queryset=Thing.objects.all(),
builder=build_thing
)
multi_typeahead = MultipleTypeaheadField(
queryset=Thing.objects.all(),
builder=build_thing
)