membershipworks: Convert EventExt.person_hours to annotation

This commit is contained in:
Adam Goldsmith 2024-01-17 13:31:10 -05:00
parent b8c2792f0a
commit 8498d311d5

View File

@ -4,7 +4,7 @@ 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, F, OuterRef, Subquery, Sum
from django.db.models import Exists, ExpressionWrapper, F, OuterRef, Subquery, Sum
from django.utils import timezone
@ -426,6 +426,11 @@ class EventExtManager(models.Manager["EventExt"]):
.values("d")[:1],
output_field=models.DurationField(),
),
person_hours=ExpressionWrapper(
ExpressionWrapper(F("duration"), models.IntegerField())
* F("count"),
models.DurationField(),
),
)
)
@ -448,14 +453,6 @@ class EventExt(Event):
max_digits=13, decimal_places=4, default=0
)
# TODO: ideally this would be a generated column or annotation,
# but I couldn't get the types to work out
@property
def person_hours(self):
if self.duration is None:
return None
return self.count * self.duration
class Meta:
verbose_name = "event"