how-to-create-search-option-in-django-3

How to create search field in django admin

Hello World, Welcome to ProjectsPlaza.com. Today we will discuss how to create a search field in the Django admin panel. I am using Django 3. Django is a very powerful MVT (Model View Template) web Framework built with python. It comes with lots of features.

For creating a search option in the Django admin panel, We just need to activate the search features. If you have not created an admin panel in Django then please have a look at the following tutorial ?.

How to create an admin panel in Django 3


Activate the search feature in the admin panel

  • Please openĀ your_app/admin.py
  • Suppose you have created a Video ModelĀ and you want to make video title searchable in the admin panel.
  • Create the following class before register your Video Model in the admin.
class VideoAdminModel(admin.ModelAdmin):
    search_fields=('title',)
  • Register Video Model with this class.
  • admin.site.register(Video,VideoAdminModel)

After applying these changes, you will see the search option above the videos list like following.

search-option-in-django-admin

Leave a Reply

Your email address will not be published. Required fields are marked *