How to add custom search box in Django-admin?

前端 未结 2 662
一向
一向 2020-12-25 09:49

I know this is gonna be a very basic question.

In Django, I have successfully created an admin panel. Now I want to add a custom search box in one of my field namely

相关标签:
2条回答
  • 2020-12-25 09:55

    cant reply due to low karma..

    but don't forget to register the Admin Model too, like

    admin.py

    from django.contrib import admin
    from .models import *
    
    admin.site.register([Photo, PhotoAdmin])  # It take a model or an iteratble
    
    0 讨论(0)
  • 2020-12-25 10:12

    Use the search_fields attribute of the ModelAdmin:

    class PhotoAdmin(admin.ModelAdmin):
        ...
        search_fields = ('name', 'description', 'keyword', )
    
    0 讨论(0)
提交回复
热议问题