The command can be activated by pressing cmd + K
on Mac or ctrl + K
on Windows/Linux. By default, the search functionality is limited to application and model names only.
To enable searching through model data, you need to set UNFOLD["COMMAND"]["search_models"] = True
in your configuration. However, be aware that searching through all models can be a database-intensive operation since it queries across all model data.
For a model to be searchable, you must define the search_fields
attribute on its admin class. This attribute specifies which fields will be used when searching through the model's data.
UNFOLD = {
# ...
"COMMAND": {
"search_models": True, # Default: False
"search_callback": "utils.search_callback"
"show_history": True, # Enable history
},
# ...
}
The search callback feature provides a way to define a custom hook that can inject additional content into search results. This is particularly useful when you want to search for results from external sources or services beyond the Django admin interface.
When implementing a search callback, keep in mind that you'll need to handle permissions manually to ensure users only see results they have access to.
# utils.py
from unfold.dataclasses import SearchResult
def search_callback(request, search_term):
# Do custom search, e.g. third party service
return [
SearchResult(
"title": "Some title",
"description": "Extra content",
"link": "https://example.com",
"icon": "database",
)
]
The command history feature can be enabled by setting show_history
to True
in the configuration. By default, this setting is disabled (False
). When enabled, users can view their previous search queries.
Search history is stored in the browser's localStorage
. Before enabling this feature, carefully consider any potential security implications of storing search queries client-side, as sensitive information could be exposed if the localStorage
is compromised.
© 2023 - 2025 Created by unfoldadmin.com. All rights reserved.