Parameters to FilterView from template redirect
I've read through all similar Q&As but can't figure out how to achieve what I'm wanting.
My base.html has a dropdown menu based on academic years:
<div class="dropdown">
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#archive"/></svg>
<strong>Select Year</strong>
</a>
<ul class="dropdown-menu dropdown-menu-dark text-small shadow">
{% for year in years %}
<li><a class="dropdown-item"href="{% url 'administration.home_selected' year %}">{{year}}</a></li>
{% endfor %}
</ul>
</div>
administration.home_selected is a function based view and receives the parameter of year to show the desired data relating to that academic year:
url.py
path(
"home_selected/<int:year>",
views.home_selected,
name="administration.home_selected",
),
How do I replicate the same functionality when a navigation tabs within the home_selected.html is selected and relates a FilterView:
path(
"learners/<int:year>",
views.FilteredLearnerListView.as_view(),
name="administration.learners",
),
The view is currently coded to show only current year data but I'd like to be able to do the same as I have with the function based view to show the correct data depending on the year selected from the base.html
views.py
class FilteredLearnerListView(SingleTableMixin, FilterView):
table_class = LearnerTable
model = Learner
context_object_name = "learner_list"
current = AcademicYear.objects.filter(is_current=True).get()
contracts_list = Contract.objects.filter(academic_year=current).values_list(
"id", flat=True
)
contracts_list = list(contracts_list)
contracts = Contract.objects.filter(academic_year=current).values()
groups = Group.objects.filter(contractId__in=contracts_list)
queryset = Learner.objects.filter(groupId__in=groups)
template_name = "learner_list.html"
filterset_class = LearnerFilter
filters.py
class LearnerFilter(FilterSet):
class Meta:
model = Learner
fields = {"surname": ["iexact"], "groupId": ["exact"]}
Please forgive any beginner errors. I'm eager to learn.