Home > Net >  django admin search by foreign key in add form
django admin search by foreign key in add form

Time:03-02

In the form to add new objects in Django admin, sometimes there are linked foreign keys that are selectable in a dropdown. Is there a way to include a searchbox for the foreign keys within the form?

For example, let's say I have a Book model with a foreign key to Author object. Instead of scrolling through all the author ids when I create a new Book object, can I search for Author "James" specifically?

CodePudding user response:

Use autocomplete fields in your custom admin.

Django Documentation - Autocomplete Fields

  • Related