Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.28 KB

README.md

File metadata and controls

42 lines (29 loc) · 1.28 KB

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
    )