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,7 +448,10 @@ 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 (
super()
.get_queryset()
.annotate(
meeting_times__count=Subquery( meeting_times__count=Subquery(
EventMeetingTime.objects.filter(event=OuterRef("pk")) EventMeetingTime.objects.filter(event=OuterRef("pk"))
.values("event__pk") .values("event__pk")
@ -464,16 +467,18 @@ class EventExtManager(models.Manager["EventExt"]):
output_field=models.DurationField(), output_field=models.DurationField(),
), ),
person_hours=ExpressionWrapper( person_hours=ExpressionWrapper(
ExpressionWrapper(F("duration"), models.IntegerField()) * F("count"), ExpressionWrapper(F("duration"), models.IntegerField())
* F("count"),
models.DurationField(), 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