Extend session search

This commit is contained in:
Lukáš Kucharczyk 2024-11-09 23:52:09 +01:00
parent 832bb48983
commit 2d3ea714c4
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@ from typing import Any
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db.models import Q
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string from django.template.loader import render_to_string
@ -39,7 +40,13 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
sessions = Session.objects.order_by("-timestamp_start") sessions = Session.objects.order_by("-timestamp_start")
search_string = request.GET.get("search_string", search_string) search_string = request.GET.get("search_string", search_string)
if search_string != "": if search_string != "":
sessions = sessions.filter(purchase__edition__name__icontains=search_string) sessions = sessions.filter(
Q(purchase__edition__name__icontains=search_string)
| Q(purchase__edition__game__name__icontains=search_string)
| Q(purchase__platform__name__icontains=search_string)
| Q(device__name__icontains=search_string)
| Q(device__type__icontains=search_string)
)
last_session = sessions.latest() last_session = sessions.latest()
page_obj = None page_obj = None
if int(limit) != 0: if int(limit) != 0: