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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83af88544249f3af51b56066d615d71c6a73ba8f4ddff6d6af27198d3c7f190a |
|
MD5 | 0d3cff79b6a7e012cc319b76cfc0a71f |
|
BLAKE2b-256 | 73dacf124b8182fa886e93f471bb15b9bc131f75b7931f2a0595c099d6fa8a19 |
Close
Hashes for django_admin_site_search-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bb1cbe6fa8d1affc57acb90df2392e922cb7a300036df4eaca579571f3c3126 |
|
MD5 | 977fe917694938040995e17f3a87a888 |
|
BLAKE2b-256 | 4ecd7d0b3e882d46d3d75d4a5fc5f6f37a428e16c95284bb27a5cf0b1cefe23e |