Master the Django Unfold command palette for quick navigation and search. Configure model search, custom callbacks, history tracking, and optimize search functionality for enhanced admin productivity.
The command palette is a powerful search and navigation tool in Django Unfold that provides instant access to applications, models, and data. Activate it with keyboard shortcuts for rapid navigation through your admin interface.
By default, the command palette searches only application and model names. To enable more comprehensive search functionality, configure the COMMAND settings.
settings.py
UNFOLD = { "COMMAND": { "search_models": False, # Search through model data "search_callback": None, # Custom search function "show_history": False, # Show search history },}
def get_searchable_models(request): """ Return list of searchable models based on user permissions. """ models = [] # Admins can search all models if request.user.is_superuser: models.extend([ "customers.customer", "products.product", "orders.order", "invoices.invoice", ]) # Regular users have limited search else: models.extend([ "customers.customer", "orders.order", ]) return models
Define a function that returns a list of SearchResult objects.
utils.py
from unfold.dataclasses import SearchResultdef search_callback(request, search_term): """ Inject custom search results into the command palette. Args: request: The current HTTP request search_term: The user's search query Returns: List of SearchResult objects """ results = [] # Search external API if "api" in search_term.lower(): results.append( SearchResult( title="API Documentation", description="View API endpoints and usage", link="https://api.example.com/docs", icon="code", ) ) # Search help documentation if "help" in search_term.lower(): results.append( SearchResult( title="Help Center", description="Get help and support", link="/help/", icon="help", ) ) return results
Search history is stored in the browser’s localStorage. Consider security implications before enabling this feature, as sensitive search terms may be exposed if localStorage is compromised.
The command palette uses infinite scrolling with a default page size of 100 results. When the last item becomes visible, the next page is automatically loaded.
Pagination is handled automatically by the command palette. No additional configuration is required.