Skip to content

Commit 04751c8

Browse files
authored
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
1 parent 9b4dedd commit 04751c8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sponsors/admin.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ def has_delete_permission(self, request, obj=None):
246246
return True
247247
return obj.open_for_editing
248248

249-
def get_queryset(self, *args, **kwargs):
250-
qs = super().get_queryset(*args, **kwargs)
251-
return qs.select_related("sponsorship_benefit__program", "program")
249+
def get_queryset(self, request):
250+
#filters the available benefits by the benefits for the year of the sponsorship
251+
match = request.resolver_match
252+
sponsorship = self.parent_model.objects.get(pk=match.kwargs["object_id"])
253+
year = sponsorship.year
254+
255+
return super().get_queryset(request).filter(sponsorship_benefit__year=year)
252256

253257

254258
class TargetableEmailBenefitsFilter(admin.SimpleListFilter):

0 commit comments

Comments
 (0)