Skip to main content

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.

Preview/demo GIF

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

  1. Install with your package manager, e.g. pip install django-admin-site-search.
  2. Add admin_site_search to your INSTALLED_APPS setting.

2. Add View

  1. If you haven't already, override/extend the default AdminSite.
  2. 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

  1. If you haven't already, create admin/base_site.html in your templates/ directory.
  2. 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 as match_model, match_objects, etc. can be extended to add any custom logic.
  • The placement of modal.html and button.html are not strict, though the former would ideally be in a top-level position.
    • Django 4.x exposes {% block header %} - this is preferable to footer.

Screenshots

Desktop, light theme, modal open

Mobile, light theme, modal closed Mobile, dark theme, modal open

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-admin-site-search-0.1.0.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

django_admin_site_search-0.1.0-py3-none-any.whl (12.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page