[Fixed]-Django Admin: change select box for foreign key to search autocomplete, like search objects

22👍

Since Django 2.0, you can use autocomplete_fields to generate autocomplete fields for foreign keys.

class UserAdmin(admin.ModelAdmin):
    search_fields = ['username', 'email']

class RedAdmin(admin.ModelAdmin):
    autocomplete_fields = ['customer']

10👍

Django has no built-in autocomplete functionality for foreign keys on admin but the raw_id_fields option may help:

class RedAdmin(admin.ModelAdmin):
    raw_id_fields = ("customer", )

If you want real autocomplete then you have to use 3rd-party app like django-autocomplete-light or some of the other solutions.

Leave a comment