From 1212dca845c4cc3fe0b150866924fefda9661407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=91=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=B5=D0=B2?= <55459712+bratusev07@users.noreply.github.com> Date: Thu, 29 Oct 2026 09:40:08 +0300 Subject: [PATCH] feat: Search and sort logic added --- apps/games/templates/games/game_detail.html | 93 ++++++++++++++++----- apps/games/templates/games/game_list.html | 20 +++++ apps/games/views.py | 20 ++++- 3 files changed, 110 insertions(+), 23 deletions(-) diff --git a/apps/games/templates/games/game_detail.html b/apps/games/templates/games/game_detail.html index 49728af..0633456 100644 --- a/apps/games/templates/games/game_detail.html +++ b/apps/games/templates/games/game_detail.html @@ -69,28 +69,81 @@
{{ game.description|linebreaks }}
- {% with screenshots=game.screenshots.all %} - {% if screenshots %} -
-

Скриншоты

+ +{% with screenshots=game.screenshots.all %} + {% if screenshots %} +
-
- - {% for screenshot in screenshots %} -
- - Скриншот {{ game.title }} - -
- {% endfor %} +

Скриншоты

+ +
+ + + + + +
+ + + {% endif %} +{% endwith %} +

Файл приложения

diff --git a/apps/games/templates/games/game_list.html b/apps/games/templates/games/game_list.html index 4e31262..5c2b6d4 100644 --- a/apps/games/templates/games/game_list.html +++ b/apps/games/templates/games/game_list.html @@ -18,6 +18,26 @@

+ +
+ + +
diff --git a/apps/games/views.py b/apps/games/views.py index da3a10b..96c30b4 100644 --- a/apps/games/views.py +++ b/apps/games/views.py @@ -1,6 +1,6 @@ from django.views.generic import ListView, DetailView -from django.db.models import F +from django.db.models import F, query from django.http import FileResponse, Http404 from django.shortcuts import get_object_or_404 @@ -18,10 +18,24 @@ class GameListView(ListView): def get_queryset(self): queryset = Game.objects.filter(status=Game.STATUS_PUBLISHED) - query = self.request.GET.get("q") + query = self.request.GET.get("q", "").strip() if query: - queryset = queryset.filter(title__icontains=query) + from django.db.models import Q + queryset = queryset.filter( + Q(title__icontains=query) + | Q(author_name__icontains=query) + ) + + sort = self.request.GET.get("sort", "updated") + + if sort == "title_asc": + queryset = queryset.order_by("title") + elif sort == "title_desc": + queryset = queryset.order_by("-title") + else: + queryset = queryset.order_by("-updated_at") + return queryset