0

I'm trying to implement django_autocomplete_light into one of my modelform's ModelMultipleChoiceFields. I've followed the tutorial and docs exactly but when I enter the first few letters into the field, a dropdown does not appear.

models.py:

class GameForm(forms.Form):
    Players = forms.ModelMultipleChoiceField(queryset=User.objects.all(),widget=autocomplete_light.MultipleChoiceWidget('UserAutocomplete'))

autocomplete_light_registry.py:

class UserAutocomplete(autocomplete_light.AutocompleteModelBase):
    search_fields=['username' ]
    model = User
    choices = User.objects.all()

autocomplete_light.register(UserAutocomplete,
    search_fields=['username'],
    attrs={
        'placeholder': 'Who?',
        'data-autocomplete-minimum-characters': 1,
    },
    widget_attrs={
        'data-widget-maximum-values': 4,
        'class': 'modern-style',
    },
)

Visiting localhost/autocomplete/UserAutocomplete/ returns all Users in a single line with no spaces:

user1user2user3

I have already done the steps stated in the installation instructions which are

  • Install the django-autocomplete-light>=2.0.0pre package with pip
  • Append 'autocomplete_light' to settings.INSTALLED_APPS before django.contrib.admin
  • Include autocomplete_light.urls
  • Include autocomplete_light/static.html after loading jquery.js (>=1.7)
user700077
  • 93
  • 2
  • 9

1 Answers1

0

I think that you didn't properly include js and static files. First you have to add js files and add {% include 'autocomplete_light/static.html' %}

kozlone
  • 111
  • 8