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):