+
-
+
+
+
+
diff --git a/pythonz/apps/templates/static/suggest_results.html b/pythonz/apps/templates/static/suggest_results.html
new file mode 100644
index 0000000..171aee4
--- /dev/null
+++ b/pythonz/apps/templates/static/suggest_results.html
@@ -0,0 +1,5 @@
+{% for item in results %}
+
+{% endfor %}
\ No newline at end of file
diff --git a/pythonz/apps/views/search.py b/pythonz/apps/views/search.py
index 951948b..ef73f50 100644
--- a/pythonz/apps/views/search.py
+++ b/pythonz/apps/views/search.py
@@ -4,12 +4,28 @@
from django.http import HttpResponse
from django.shortcuts import redirect
from django.shortcuts import render
+from siteajax.decorators import ajax_dispatch
+from siteajax.utils import AjaxResponse
from ..generics.views import HttpRequest
from ..models import Reference, ReferenceMissing, Category, Person, App
from ..utils import message_warning, search_models
+def suggest(request):
+ search_term, results = search_models(
+ request.POST.get('text', ''), search_in=(
+ Category,
+ Person,
+ Reference,
+ App,
+ ))
+ if len(results) > 5:
+ results = results[:5]
+ return render(request, 'static/suggest_results.html', {'results': results})
+@ajax_dispatch({
+ 'tags': suggest
+})
def search(request: HttpRequest) -> HttpResponse:
"""Страница с результатами поиска по справочнику.
Если найден один результат, перенаправляет на страницу результата.
diff --git a/pythonz/urls.py b/pythonz/urls.py
index 41fef4d..b21e08c 100644
--- a/pythonz/urls.py
+++ b/pythonz/urls.py
@@ -14,6 +14,7 @@
from .apps.realms import bootstrap_realms
from .apps.views import page_not_found, permission_denied, server_error, index, search, login, telebot, user_settings
+from .apps.views.search import suggest
urls_password_reset = [
path('password_reset/', PasswordResetView.as_view(), name='password_reset'),