From 187e958b60983941c25fb2e3fb631866ac1a67ca Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 15 Feb 2022 21:43:19 -0500 Subject: [PATCH] [paperwork] Use a ListView for member certifications --- paperwork/urls.py | 2 +- paperwork/views.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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)