jeudi 30 juin 2016

Select2 Autocomplete widget not showing complete list

I've tried using django-autocomplete-light in my project's admin page. I've installed the autocomplete url as explained and as far as I can tell the autocomplete works fine.

url('plant_autocomplete/$',
 autocomplete.Select2QuerySetView.as_view(model=Plant),name='plant_autocomplete',)

My problem is that when I hooked the autocomplete to the admin page, the drop-down list contained just the currently saved value, and not all possible values as its supposed to.

when hooked up to autocomplete

when hooked up to autocomplete

all possible values (should be appearing in the autocomplete) values that should be appearing

Admin form code

class TestForm(forms.ModelForm):
    class Meta:
        model = PlantImage
        fields = ('plant_id', 'owner')
        widgets = {
            'plant_id': autocomplete.ModelSelect2(url='plant_autocomplete')
        }

class PlantImageAdmin(admin.ModelAdmin):
    form = TestForm
admin.site.register(PlantImage, PlantImageAdmin)

Aucun commentaire:

Enregistrer un commentaire