django search admin autocomplete
vments & Bug fixes
简单的 django 应用程序,添加自动完成功能以在管理面板内进行搜索。
pip install django-search-admin-autocomplete
# OR
pip install git+https://github.com/linevych/django-search-admin-autocomplete.git
INSTALLED_APPS = [
...
'search_admin_autocomplete' ,
...
]
from search_admin_autocomplete . admin import SearchAutoCompleteAdmin
class MyModelAdmin ( SearchAutoCompleteAdmin )
search_fields = [ 'search_field' , ]
admin . site . register ( MyModel , MyModelAdmin )
如果admin/change_list.html是自定义的
管理员.py
from search_admin_autocomplete . admin import SearchAutoCompleteAdmin
class MyModelAdmin ( SearchAutoCompleteAdmin )
change_list_template = 'admin/custom-list.html'
search_fields = [ 'search_field' , ]
admin . site . register ( MyModel , MyModelAdmin )
管理/自定义列表.html
{% extends 'search_admin_autocomplete/change_list.html' %}
{% block object-tools %}
Your custom html...
{{ block.super }}
{% endblock %}
该项目支持 MyPy,但要运行类型检查,您需要 Python 3.6+。
pip install - r requirements_dev . txt
PYTHONPATH = "$PYTHONPATH:$PWD/example" mypy search_admin_autocomplete