Skip to content

Commit

Permalink
Add filter to TechGroup's Event prefetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
KGB33 committed Sep 2, 2024
1 parent 9c3b258 commit 09f3dc3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib import messages
from django.contrib.auth.mixins import UserPassesTestMixin
from django.db.models import Prefetch
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.template import loader
Expand Down Expand Up @@ -164,7 +165,9 @@ class DetailTechGroup(HtmxViewMixin, DetailView):
model = TechGroup

def __init__(self, **kwargs: Any) -> None:
self.queryset = TechGroup.objects.prefetch_related("event_set")
self.queryset = TechGroup.objects.prefetch_related(
Prefetch("event_set", Event.objects.filter(date_time__gte=timezone.localtime()))
)
super().__init__(**kwargs)

def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
Expand Down

0 comments on commit 09f3dc3

Please sign in to comment.