A search (cmd+k) modal, for the Django admin UI, that searches your entire site.
Project description
django-admin-site-search
A 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 fields.
- Object Char and Text fields (with
__icontains
).
- 🔒 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.
- Uses Django's built-in CSS vars to match your admin theme.
Requirements
- Python 3.8 - 3.11.
- Django 3.2 - 4.1.
Setup
1. Install
- Install with your package manager, e.g.
pip install django-admin-site-search
. - Add
admin_site_search
to yourINSTALLED_APPS
setting.
2. Add View
- If you haven't already, override/extend the default AdminSite.
- Add the
AdminSiteSearchView
to your AdminSite:
from django.contrib import admin
from admin_site_search.views import AdminSiteSearchView
class MyAdminSite(AdminSiteSearchView, admin.AdminSite):
...
3. Add Templates
- If you haven't already, create
admin/base_site.html
in yourtemplates/
directory. - Include the
admin_site_search
templates:
{% 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 %}
Notes
- Along with styles, the
admin_site_search/head.html
loads Alpine JS.- This is the only external dependency.
- Search is implemented with basic
icontains
/in
logic. Full-text search is out-of-scope. - Methods in
AdminSiteSearchView
; such asmatch_model
,match_objects
, etc. can be extended to add any custom logic. - The placement of
modal.html
andbutton.html
are not strict, though the former would ideally be in a top-level position.- Django 4.x exposes
{% block header %}
- this is preferable tofooter
.
- Django 4.x exposes
Screenshots
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-admin-site-search-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8cf6853b2a49d42edcd1a5b5d437e02016159e1395d4c3bf125799041351160 |
|
MD5 | e16c2f814efce68fd6f213fe05f9e1b4 |
|
BLAKE2b-256 | 3a014c7e2b8494d1a347c967e11a6818cdcf0f7e512019600ba038004bef0c56 |
Close
Hashes for django_admin_site_search-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623ef371285e7be4c5559495a93f9b82b2b8e3152207d1664ac7e54640c37dbd |
|
MD5 | d6a2a9a13ccb84cf6bbed25e81fcb870 |
|
BLAKE2b-256 | b9a8e7f4a83152791f5755cb20d3833148f497b63b88562a694ae6eb7e901e3b |