From 04751c86869f9653b65230a7e0028e7d3abd6009 Mon Sep 17 00:00:00 2001 From: Jessie <70440141+jessiebelle@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:24:47 +0200 Subject: [PATCH] 2342 display only benefits associated with the year of the sponsorship package being edited (#2356) * WIP * WIP * WIP * we finally got there with the qs filter * removing redundant tests * removing unused imports * missed one --- sponsors/admin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sponsors/admin.py b/sponsors/admin.py index d6601140f..88aff8c57 100644 --- a/sponsors/admin.py +++ b/sponsors/admin.py @@ -246,9 +246,13 @@ def has_delete_permission(self, request, obj=None): return True return obj.open_for_editing - def get_queryset(self, *args, **kwargs): - qs = super().get_queryset(*args, **kwargs) - return qs.select_related("sponsorship_benefit__program", "program") + def get_queryset(self, request): + #filters the available benefits by the benefits for the year of the sponsorship + match = request.resolver_match + sponsorship = self.parent_model.objects.get(pk=match.kwargs["object_id"]) + year = sponsorship.year + + return super().get_queryset(request).filter(sponsorship_benefit__year=year) class TargetableEmailBenefitsFilter(admin.SimpleListFilter):