Skip to main content

Global search for Django Admin, search across all registered models with permissions and search_fields support

Project description

Django Global Search

PyPI Python Version Django Version License

A global search extension for Django Admin that allows searching across multiple models from a single page. Search through all registered models with permission handling and respect for existing search_fields configurations.

Documentation can be found at https://django-global-search.readthedocs.io/

Features

  • Unified Search Interface - Search across multiple models from a single page
  • Django Admin Integration - Seamlessly integrates with Django Admin UI
  • Model Selection - Filter search by specific models or apps

Installation

Install using pip:

pip install django-global-search

Or using uv:

uv add django-global-search

Usage

Basic Setup (Automatic Integration)

  1. Add django_global_search to your INSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django_global_search',  # Add after admin
    # ... other apps
]
  1. The global search will be automatically available at /admin/global-search/

That's it! The package will automatically inject itself into the default Django admin site.

Adding a Navigation Button (Optional)

Add a search button to the admin interface by creating templates/admin/base_site.html:

{% extends "admin/base_site.html" %}

{% block userlinks %}
    {{ block.super }}
    {% include 'global_search/button.html' %}
{% endblock %}

This adds a convenient "Global Search" button in the admin header.

Advanced Setup (Custom Admin Site)

If you're using a custom admin site, you can explicitly inherit from the mixin:

# admin.py
from django.contrib.admin import AdminSite
from django_global_search.admin import GlobalSearchAdminSiteMixin

class MyAdminSite(GlobalSearchAdminSiteMixin, AdminSite):
    site_header = "My Custom Admin"

# Replace the default admin site
admin_site = MyAdminSite(name='myadmin')
# urls.py
from myproject.admin import admin_site

urlpatterns = [
    path('admin/', admin_site.urls),
]

Configuration

Configure global search behavior in your settings.py:

# Minimum query length (default: 2)
GLOBAL_SEARCH_MIN_QUERY_LENGTH = 2

# Maximum results per model (default: 10)
GLOBAL_SEARCH_MAX_RESULTS_PER_MODEL = 10

# Search timeout in milliseconds (default: 20000)
GLOBAL_SEARCH_TIMEOUT_MS = 20000

# Exclude specific models from search
GLOBAL_SEARCH_EXCLUDED_MODELS = [
    'admin.logentry',
    'auth.permission',
    'contenttypes.contenttype',
]

# Disable automatic injection (if using custom admin site)
GLOBAL_SEARCH_INJECT_DEFAULT_ADMIN_SITE_ENABLED = False

Model Configuration

No additional configuration needed. automatically uses your existing ModelAdmin settings:

from django.contrib import admin
from .models import Article

@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    search_fields = ['title', 'content', 'author__name']  # Used by global search
    list_display = ['title', 'author', 'published_date']

How It Works

  1. Automatic Model Detection - Discovers all registered ModelAdmin classes
  2. Permission Checking - Filters models based on user's view/change permissions
  3. Search Execution - Uses Django's built-in get_search_results() method
  4. Result Aggregation - Groups results by app and model
  5. Performance Control - Applies timeout and result limits to prevent slow queries

Screenshots

Global Search Interface

Global Search Interface

Search across all models with permission-based filtering and model selection

Search Results

Search Results

Results grouped by app and model with direct links to detail and changelist views

Requirements

  • Python 3.9+
  • Django 4.2+

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/2ykwang/django-global-search.git
cd django-global-search

# Install dependencies
uv sync

# Run linter
just lint

# Format code
just format

# Build package
just build

Documentation

# Serve documentation locally
just docs-serve

# Build documentation
just docs-build

# Deploy to GitHub Pages
just docs-deploy

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

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_global_search-0.0.3.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_global_search-0.0.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file django_global_search-0.0.3.tar.gz.

File metadata

File hashes

Hashes for django_global_search-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c0506f7c3413e231861cd03e92161c1ff585b327312753a43cd4354911225c4c
MD5 b2ee1ec8adf0ada9f342d7a6e4f1fa8a
BLAKE2b-256 0cb5f1751d8b0487bdd73e5e02c22a0b58bbc70ab095ba1594cd76155cdfcdf7

See more details on using hashes here.

File details

Details for the file django_global_search-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_global_search-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 faed980a46828fee53c946204ac984f6069858a5583cd916abaf2dbcacde1599
MD5 caeaf3627b4d73911c106e2f9cfdd31d
BLAKE2b-256 1f210d057f088c644eff5a3ae67fe3d783e97755f1c29f74f875d20f1d6e5f69

See more details on using hashes here.

Supported by

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