[Django]-Django autocomplete_fields doesn't work in TabularInline (but works in StackedInline)

0👍

You can use django-autocomplete-light lib
https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html

from dal import autocomplete

from django import forms


class PersonForm(forms.ModelForm):
    class Meta:
        model = Person
        fields = ('__all__')
        widgets = {
            'birth_country': autocomplete.ModelSelect2(url='country-autocomplete')
        }

Using autocompletes in the admin We can make ModelAdmin to use our
form, ie:

from django.contrib import admin

from your_person_app.models import Person
from your_person_app.forms import PersonForm


class PersonAdmin(admin.ModelAdmin):
    form = PersonForm

admin.site.register(Person, PersonAdmin)

Note that this also works with inlines, ie:

class PersonInline(admin.TabularInline):
    model = Person
    form = PersonForm

Leave a comment