feat: added text search for title and description
This commit is contained in:
@@ -59,6 +59,18 @@
|
||||
<option value="closed" {% if selected_status == "closed" %}selected{% endif %}>Erledigt</option>
|
||||
</select>
|
||||
</form>
|
||||
<form method="get" style="margin-bottom: 1.5rem;">
|
||||
<input type="text" name="q" placeholder="🔍 Suche nach Titel oder Beschreibung"
|
||||
value="{{ search_query }}" style="padding: 0.4rem; width: 60%; max-width: 300px;">
|
||||
{% if selected_status %}
|
||||
<input type="hidden" name="status" value="{{ selected_status }}">
|
||||
{% endif %}
|
||||
<button type="submit">Suchen</button>
|
||||
</form>
|
||||
|
||||
{% if search_query %}
|
||||
<p>Ergebnisse für „<strong>{{ search_query }}</strong>“:</p>
|
||||
{% endif %}
|
||||
|
||||
{% for ticket in tickets %}
|
||||
<div class="ticket-item">
|
||||
|
||||
@@ -8,6 +8,7 @@ from django.urls import reverse
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.db.models import Q
|
||||
|
||||
from .models import Ticket, TicketHistory
|
||||
|
||||
@@ -16,24 +17,32 @@ class HomeView(TemplateView):
|
||||
template_name = "ticketsystem/home.html"
|
||||
|
||||
|
||||
class TicketListView(LoginRequiredMixin, ListView):
|
||||
class TicketListView(ListView):
|
||||
model = Ticket
|
||||
template_name = "ticketsystem/index.html"
|
||||
context_object_name = "tickets"
|
||||
ordering = ["-created_at"] # neueste zuerst
|
||||
paginate_by = 10 # optional: Pagination (10 Tickets pro Seite)
|
||||
ordering = ["-created_at"]
|
||||
paginate_by = 10
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
status = self.request.GET.get("status")
|
||||
query = self.request.GET.get("q")
|
||||
|
||||
if status:
|
||||
queryset = queryset.filter(status=status)
|
||||
|
||||
if query:
|
||||
queryset = queryset.filter(
|
||||
Q(title__icontains=query) | Q(description__icontains=query)
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["selected_status"] = self.request.GET.get("status", "")
|
||||
context["search_query"] = self.request.GET.get("q", "")
|
||||
return context
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user