Add a name search box to the Families list

Matches a first or last name against any visible member on the
family -- parent/guardian or child -- narrowing the same
members_visible_to() set the unfiltered list already uses, so a
match still respects who the requester is allowed to see. Pagination
was already wired up; the shared pager already preserves ?q= on page
links.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-12 08:57:30 +02:00
parent ece39e51ed
commit 9901a90266
3 changed files with 61 additions and 1 deletions

View File

@@ -1376,10 +1376,20 @@ class FamilyListView(ClubStaffRequiredMixin, ListView):
def get_queryset(self):
visible = members_visible_to(self.request.user, self.request.club, include_guardians=True)
# ?q= matches a first or last name of any member on the family --
# parent/guardian or child alike, since the person being searched for
# could be either. Narrowing the already-visible set first (rather than
# filtering families on a second, independent membership join) means a
# match still respects the same visibility rule as the unfiltered list.
search = self.request.GET.get("q", "").strip()
if search:
visible = visible.filter(Q(first_name__icontains=search) | Q(last_name__icontains=search))
return families_of_club(self.request.club).filter(memberships__member__in=visible).distinct()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = super().get_context_data(search=self.request.GET.get("q", ""), **kwargs)
families = list(context["families"])
visible = members_visible_to(self.request.user, self.request.club, include_guardians=True)