Package: django-admin-site-search
django-admin-site-searchA global/site search modal for the Django admin.Features🎩 Works out-of-the-box, with minimal config.🔎 Search performed on:App labels.Model labels and field attributes.CharFieldvalues (with__icontains).Subclasses also included:SlugField,URLField, etc.🔒 Built-in auth: users can only search apps and models that they have permission to view.⚡ Results appear on-type, with throttling/debouncing to avoid excessive requests.🎹 Keyboard navigation (cmd+k, up/down, enter).✨ Responsive, and supports dark/light mode.Django's built-in CSS vars are used to match your admin theme.RequirementsPython 3.7 - 3.11.Django 3.2 - 4.2.Setup1. InstallInstall with your package manager, e.g.pip install django-admin-site-search.Addadmin_site_searchto yourINSTALLED_APPSsetting.2. Add ViewIf you haven't already,override/extend the default AdminSite.Add theAdminSiteSearchViewto your AdminSite:fromdjango.contribimportadminfromadmin_site_search.viewsimportAdminSiteSearchViewclassMyAdminSite(AdminSiteSearchView,admin.AdminSite):...By default, the search route is at<admin_path>/search/. The last part can be changed by overriding
thesite_search_pathclass variable in your admin site.3. Add TemplatesIf you haven't already, createadmin/base_site.htmlin yourtemplates/directory.Note: if yourtemplates/directory is inside of an app, then that app must appear inINSTALLED_APPSbeforeyour custom admin app.Include theadmin_site_searchtemplates:{% extends "admin/base_site.html" %}

{% block extrahead %}
    {% include 'admin_site_search/head.html' %}
    {{ block.super }}
{% endblock %}

{% block footer %}
    {{ block.super }}
    {% include 'admin_site_search/modal.html' %}
{% endblock %}

{% block usertools %}
    {% include 'admin_site_search/button.html' %}
    {{ block.super }}
{% endblock %}NotesAlong with styles,admin_site_search/head.htmlloadsAlpine JS.This is bundled into/static/, to avoid external dependencies.The placement ofmodal.htmlandbutton.htmlare not strict, though the former would ideally be in a top-level
position.Django 4.x exposes{% block header %}- this is preferable tofooter.CustomisationMethods inAdminSiteSearchViewcan be extended to add custom logic.defmatch_app(self,query:str,name:str)->bool:"""DEFAULT: case-insensitive match the app name"""...defmatch_model(self,query:str,name:str,object_name:str,fields:List[Field])->bool:"""DEFAULT: case-insensitive match the model and field attributes"""...defmatch_objects(self,query:str,model_class:Model,model_fields:List[Field])->QuerySet:"""DEFAULT: Returns the QuerySet after performing an OR filter across all Char fields in the model."""...deffilter_field(self,query:str,field:Field)->Optional[Q]:"""DEFAULT: Returns a Q 'icontains' filter for Char fields, otherwise None"""...defget_model_class(self,app_label:str,model_dict:dict)->Optional[Model]:"""DEFAULT: Retrieve the model class from the dict created by admin.AdminSite"""...ExampleAddTextFieldresults to search.fromdjango.contribimportadminfromdjango.db.modelsimportQ,Field,TextFieldfromadmin_site_search.viewsimportAdminSiteSearchViewclassMyAdminSite(AdminSiteSearchView,admin.AdminSite):...deffilter_field(self,query:str,field:Field)->Optional[Q]:"""Extends super() to add TextField support to site search"""ifisinstance(field,TextField):returnQ(**{f"{field.name}__icontains":query})returnsuper().filter_field(query,field)Note that this isn't done by default for performance reasons:__icontainson a
large number of text entries is inefficient.Screenshots