How to use autocomplete on dropdownlist of ForeignKey field on my custom page


As I see, we can apply autocomplete_fields for ForeignKey field on as the figure below. Employee model is ForeignKey field on Incident_Detail Model.
Apparently , we can search employee name on dropdowlist in admin page as figure shown in below.

My requirement is that

I want to implement autocomplete on dropdown list of ForeignKey field like on my custom page.

How to configure and code in views,py , , and ,mycustom_templete.html

Anyone can advise guidelines or sample code?

The figure below is my custom form.

Thank you a lot.

1 Like

Actually, the best sample code available would be the admin page itself. You can bring up that page in your browser to see the JavaScript being used, and then look at the views in django.contrib.admin to see how it’s handled on the server.

Also see Form Assets (the Media class) | Django documentation | Django for some breadcrumbs as to how to use those admin widgets in your own page.

I try django-ajax-selects · PyPI
It saves my time to is very close to your recommendation.

Thank you for your advice.