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

**URL:** <https://forum.djangoproject.com/t/how-to-use-autocomplete-on-dropdownlist-of-foreignkey-field-on-my-custom-page/7884>\
**Category:** Using Django\
**Created:** [May 12, 2021, 6:49am UTC](https://forum.djangoproject.com/t/how-to-use-autocomplete-on-dropdownlist-of-foreignkey-field-on-my-custom-page/7884 "2021-05-12T06:49:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [May 12, 2021, 6:49am UTC](https://forum.djangoproject.com/t/how-to-use-autocomplete-on-dropdownlist-of-foreignkey-field-on-my-custom-page/7884/1 "2021-05-12T06:49:01Z")

</div>

Hi

As I see, we can apply autocomplete\_fields for ForeignKey field on admin.py 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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/8/8aa9f98e82ee4f9904b86219aa365e131576ec8d.png)

_My requirement is that_

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

_How to configure and code in views,py , forms.py , urls.py and ,mycustom\_templete.html_

Anyone can advise guidelines or sample code?

The figure below is my custom form.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/9/90c8b57c0fd357f2722227ff0e12cb5929f1903a.png)

Thank you a lot.  
Pongthorn

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 12, 2021, 1:13pm UTC](https://forum.djangoproject.com/t/how-to-use-autocomplete-on-dropdownlist-of-foreignkey-field-on-my-custom-page/7884/2 "2021-05-12T13:13:21Z")

</div>

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](https://docs.djangoproject.com/en/3.1/topics/forms/media/) for some breadcrumbs as to how to use those admin widgets in your own page.

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [May 13, 2021, 2:30pm UTC](https://forum.djangoproject.com/t/how-to-use-autocomplete-on-dropdownlist-of-foreignkey-field-on-my-custom-page/7884/3 "2021-05-13T14:30:49Z")

</div>

I try [django-ajax-selects · PyPI](https://pypi.org/project/django-ajax-selects/)  
It saves my time to do.it is very close to your recommendation.

Thank you for your advice.
