Skip to content

Commit

Permalink
2342 display only benefits associated with the year of the sponsorshi…
Browse files Browse the repository at this point in the history
…p package being edited (#2356)

* WIP

* WIP

* WIP

* we finally got there with the qs filter

* removing redundant tests

* removing unused imports

* missed one
  • Loading branch information
jessiebelle authored Jan 15, 2024
1 parent 9b4dedd commit 04751c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sponsors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 04751c8

Please sign in to comment.