Skip to content

Commit

Permalink
Add django-admin-site-search (#776)
Browse files Browse the repository at this point in the history
* Add django-admin-site-search

* switch to admin_search_fields to improve search quality
  • Loading branch information
WillNilges authored Dec 10, 2024
1 parent d90c9ca commit 1931b2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = [
"prettytable==3.11.*",
"matplotlib==3.9.*",
"django-ipware==7.0.1",
"django-admin-site-search==1.1.*",
]

[project.optional-dependencies]
Expand Down
7 changes: 5 additions & 2 deletions src/meshdb/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from typing import Any, List, Optional
from typing import Any, List, Literal, Optional

from admin_site_search.views import AdminSiteSearchView
from django.contrib import admin
from django.http import HttpRequest


class MeshDBAdminSite(admin.AdminSite):
class MeshDBAdminSite(AdminSiteSearchView, admin.AdminSite):
site_search_method: Literal["model_char_fields", "admin_search_fields"] = "admin_search_fields"

def get_app_list(self, request: HttpRequest, app_label: Optional[str] = None) -> List[Any]:
"""Reorder the apps in the admin site.
Expand Down
1 change: 1 addition & 0 deletions src/meshdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"flags",
"explorer",
"simple_history",
"admin_site_search",
]

MIDDLEWARE = [
Expand Down
14 changes: 13 additions & 1 deletion src/meshdb/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

{% block extrahead %}
<link rel="shortcut icon" href="{% static 'meshweb/favicon.png' %}" />
{% include 'admin_site_search/head.html' %}
{{ block.super }}
{% endblock %}

{% block branding %}
Expand All @@ -18,4 +20,14 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}"><img src="{% static 'meshwe
<a href="#" class="hidden" style="margin-left: 5px; vertical-align: middle; border: none;" id="show_map_button">
<img src="{% static '/admin/map/img/map.png' %}" height="16px" title="Show Map">
</a>
{% endblock %}
{% endblock %}

{% block footer %}
{{ block.super }}
{% include 'admin_site_search/modal.html' %}
{% endblock %}

{% block usertools %}
{% include 'admin_site_search/button.html' %}
{{ block.super }}
{% endblock %}

0 comments on commit 1931b2a

Please sign in to comment.