diff --git a/paperwork/urls.py b/paperwork/urls.py index 1527d01..07453c0 100644 --- a/paperwork/urls.py +++ b/paperwork/urls.py @@ -7,7 +7,7 @@ app_name = "paperwork" urlpatterns = [ path( "certifications/by_uid/", - views.member_certifications, + views.MemberCertificationListView.as_view(), name="member_certifications", ), ] diff --git a/paperwork/views.py b/paperwork/views.py index c833056..136c56a 100644 --- a/paperwork/views.py +++ b/paperwork/views.py @@ -1,12 +1,14 @@ -from django.shortcuts import render +from django.shortcuts import get_object_or_404 +from django.views.generic import ListView from membershipworks.models import Member from .models import Certification -def member_certifications(request, uid: str): - context = { - "member": Member.objects.get(uid=uid), - "certifications": Certification.objects.filter(member_id=uid), - } - return render(request, "paperwork/member_certifications.dj.html", context) +class MemberCertificationListView(ListView): + template_name = "paperwork/member_certifications.dj.html" + context_object_name = "certifications" + + def get_queryset(self): + self.member = get_object_or_404(Member, uid=self.kwargs["uid"]) + return Certification.objects.filter(member=self.member)