membershipworks: Expose EventExtQuerySet methods on EventExtManager

This commit is contained in:
Adam Goldsmith 2024-01-28 23:54:55 -05:00
parent 0eab482893
commit 21fe7f66cd

View File

@ -448,32 +448,37 @@ class EventExtQuerySet(models.QuerySet["EventExt"]):
class EventExtManager(models.Manager["EventExt"]): class EventExtManager(models.Manager["EventExt"]):
def get_queryset(self) -> models.QuerySet["EventExt"]: def get_queryset(self) -> models.QuerySet["EventExt"]:
return EventExtQuerySet(self.model, using=self._db).annotate( return (
meeting_times__count=Subquery( super()
EventMeetingTime.objects.filter(event=OuterRef("pk")) .get_queryset()
.values("event__pk") .annotate(
.annotate(d=Count("pk")) meeting_times__count=Subquery(
.values("d")[:1], EventMeetingTime.objects.filter(event=OuterRef("pk"))
output_field=models.IntegerField(), .values("event__pk")
), .annotate(d=Count("pk"))
duration=Subquery( .values("d")[:1],
EventMeetingTime.objects.filter(event=OuterRef("pk")) output_field=models.IntegerField(),
.values("event__pk") ),
.annotate(d=Sum("duration")) duration=Subquery(
.values("d")[:1], EventMeetingTime.objects.filter(event=OuterRef("pk"))
output_field=models.DurationField(), .values("event__pk")
), .annotate(d=Sum("duration"))
person_hours=ExpressionWrapper( .values("d")[:1],
ExpressionWrapper(F("duration"), models.IntegerField()) * F("count"), output_field=models.DurationField(),
models.DurationField(), ),
), person_hours=ExpressionWrapper(
ExpressionWrapper(F("duration"), models.IntegerField())
* F("count"),
models.DurationField(),
),
)
) )
class EventExt(Event): class EventExt(Event):
"""Extension of `Event` to capture some fields not supported in MembershipWorks""" """Extension of `Event` to capture some fields not supported in MembershipWorks"""
objects = EventExtManager() objects = EventExtManager.from_queryset(EventExtQuerySet)()
instructor = models.ForeignKey( instructor = models.ForeignKey(
EventInstructor, on_delete=models.PROTECT, null=True, blank=True EventInstructor, on_delete=models.PROTECT, null=True, blank=True