Choosing label in Admin autocomplete_fields widget

253 views
Skip to first unread message

Mark Rossetti

unread,
Dec 13, 2021, 9:04:00 PM12/13/21
to Django users
In Django 3.1, we were using autocomplete_fields on Admin edit pages with some foreign keys. To improve usability, we had overridden ModelAdmin.autocomplete_view so that it would provide us with human-readable labels. Very similar to the question and solution in this Stack Overflow post: https://stackoverflow.com/questions/55629887/change-django-autocomplete-fields-label

In the move to Django 3.2, ModelAdmin.autocomplete_view was removed, causing all of our autocomplete_fields widgets to show only the foreign key ID in dropdowns (making them pretty unusable).

It seems that `ModelAdmin.autocomplete_view` was an undocumented feature, so it's understandable that it was moved without explanation. Nevertheless, we're a bit stuck now. How can we choose which model field is used for the autocomplete_fields widgets in Django >=3.2?
Reply all
Reply to author
Forward
0 new messages