2

I've installed django-autocomplete-light and am trying to get it to work. I have it on the (non admin) form, but when I try to actually change the value, I get a 500 error as above.

AttributeError at /autocomplete/SeriesAutocomplete/ 'list' object has no attribute 'startswith'

Here are some relevant files:

autocomplete_light_registry.py:

import autocomplete_light
from models import Series


class SeriesAutocomplete(autocomplete_light.AutocompleteModelBase):
    search_fields = ['^title',],
    attrs = {'placeholder': 'Series name ?',}

autocomplete_light.register(Series, SeriesAutocomplete)

forms.py:

class PublicationForm(ModelForm):
    series = autocomplete_light.ModelChoiceField('SeriesAutocomplete')

    class Meta:
        model = Publication
        fields = ['title', 'series', 'dsn', 'primary_contact', 'department']

I must be missing something??

Rob L
  • 3,634
  • 2
  • 19
  • 38

2 Answers2

2

It's just a simple typo, you wrote

search_fields = ['^title',],

Which made search_fields a tuple of lists. Removing the comma should work.

search_fields = ['^title',]
Seb D.
  • 5,046
  • 1
  • 28
  • 36
1

Seems to be a funny bug. If you use a tuple instead of a list, i.e.

search_fields = ('^title',)

instead of

search_fields = ['^title',]

everything should work.

Philipp Zedler
  • 1,660
  • 1
  • 17
  • 36