From 978024c538d713c96ccbebb14ec1d209624bd462 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 17 Jan 2024 13:37:14 -0500 Subject: [PATCH] membershipworks: Annotate EventExt.meeting_times__count --- membershipworks/models.py | 11 ++++++++++- .../membershipworks/event_month_report.dj.html | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/membershipworks/models.py b/membershipworks/models.py index 88b95c1..180ed1b 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -4,7 +4,15 @@ from datetime import datetime import django.core.mail.message from django.conf import settings from django.db import models -from django.db.models import Exists, ExpressionWrapper, F, OuterRef, Subquery, Sum +from django.db.models import ( + Count, + Exists, + ExpressionWrapper, + F, + OuterRef, + Subquery, + Sum, +) from django.utils import timezone @@ -419,6 +427,7 @@ class EventExtManager(models.Manager["EventExt"]): super() .get_queryset() .annotate( + Count("meeting_times"), duration=Subquery( EventMeetingTime.objects.filter(event=OuterRef("pk")) .values("event__pk") diff --git a/membershipworks/templates/membershipworks/event_month_report.dj.html b/membershipworks/templates/membershipworks/event_month_report.dj.html index 9f1039c..31abe76 100644 --- a/membershipworks/templates/membershipworks/event_month_report.dj.html +++ b/membershipworks/templates/membershipworks/event_month_report.dj.html @@ -35,7 +35,7 @@ {{ event.category }} {{ event.count }} {{ event.cap }} - {{ event.meeting_times.count }} + {{ event.meeting_times__count }} {{ event.duration|duration_as_hours }} {{ event.person_hours|duration_as_hours }}