membershipworks: Use GeneratedField for EventMeetingTime.duration
Relevant Django bug was fixed in 5.0.1 https://code.djangoproject.com/ticket/35019
This commit is contained in:
parent
40ac6ef97f
commit
796f0d6ad1
@ -415,13 +415,7 @@ class EventInstructor(models.Model):
|
||||
|
||||
class EventExtManager(models.Manager["EventExt"]):
|
||||
def get_queryset(self) -> models.QuerySet["EventExt"]:
|
||||
return (
|
||||
super()
|
||||
.get_queryset()
|
||||
.annotate(duration=Sum(F("meeting_times__end") - F("meeting_times__start")))
|
||||
)
|
||||
# TODO: use simpler expression when GeneratedField fixed
|
||||
# return super().get_queryset().annotate(duration=Sum("meeting_times__duration"))
|
||||
return super().get_queryset().annotate(duration=Sum("meeting_times__duration"))
|
||||
|
||||
|
||||
class EventExt(Event):
|
||||
@ -446,29 +440,18 @@ class EventExt(Event):
|
||||
verbose_name = "event"
|
||||
|
||||
|
||||
class EventMeetingTimeManager(models.Manager["EventMeetingTime"]):
|
||||
def get_queryset(self) -> models.QuerySet["EventMeetingTime"]:
|
||||
return super().get_queryset().annotate(duration=F("end") - F("start"))
|
||||
|
||||
|
||||
class EventMeetingTime(models.Model):
|
||||
objects = EventMeetingTimeManager()
|
||||
|
||||
event = models.ForeignKey(
|
||||
EventExt, on_delete=models.CASCADE, related_name="meeting_times"
|
||||
)
|
||||
start = models.DateTimeField()
|
||||
end = models.DateTimeField()
|
||||
|
||||
# TODO: Should use generated field instead of manager, but this is
|
||||
# broken due to current Django bug, pending next release (> 5.0)
|
||||
# ref: https://code.djangoproject.com/ticket/35019
|
||||
|
||||
# duration = models.GeneratedField(
|
||||
# expression=F("end") - F("start"),
|
||||
# output_field=models.DurationField(),
|
||||
# db_persist=False,
|
||||
# )
|
||||
duration = models.GeneratedField(
|
||||
expression=F("end") - F("start"),
|
||||
output_field=models.DurationField(),
|
||||
db_persist=False,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
|
Loading…
Reference in New Issue
Block a user