1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-12-14 22:45:16 +01:00

Solve bug in search field

This commit is contained in:
Maxime JUST
2025-12-14 17:47:03 +01:00
parent 0c1b570d7f
commit 3489ab4595
2 changed files with 24 additions and 9 deletions

View File

@@ -15,14 +15,19 @@
<h3>{% trans "Results" %}</h3>
<div id="search-results">
{% regroup object_list by model_name as categories %}
{% for category in categories %}
<h4>{% trans category.grouper|capfirst %}</h4>
{% with table=category.list|search_table %}
{% render_table table %}
{% endwith %}
{% empty %}
{% if has_results %}
{% regroup object_list by model_name as categories %}
{% for category in categories %}
{% if category.grouper %}
<h4>{% trans category.grouper|capfirst %}</h4>
{% with table=category.list|search_table %}
{% render_table table %}
{% endwith %}
{% endif %}
{% endfor %}
{% else %}
<p>{% trans "No results found." %}</p>
{% endfor %}
{% endif %}
</div>
{% endblock %}

View File

@@ -46,4 +46,14 @@ class LoginRequiredTemplateView(LoginRequiredMixin, TemplateView):
class AdminSearchView(AdminMixin, SearchView):
pass
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
results = context["object_list"]
context["has_results"] = any(
getattr(result, "model_name", None)
for result in results
)
return context