Skip to content

aj-may/django-bootstrap-typeahead

Repository files navigation

Django Bootstrap Typeahead

Convert Django model choice fields into typeahead fields.

Typeahead inputs built on top of Django and Bootstrap.

Example

Install:

> pip install django-bootstrap-typeahead

Usage:

  • Add django_bootstrap_typeahead to the installed apps of your Django Project
  • create a form and use TypeaheadField instead of ModelChoiceField or MultipleTypeaheadField instead of ModelMultipleChoiceField
  • Be sure to include the form's required media in the template. ie. {{ form.media }}
  • Also be sure to include Twitter Bootstrap

Example:

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
    )

About

Convert Django model choice fields into typeahead fields.

Resources

License

Stars

Watchers

Forks

Packages

No packages published