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"]):
|
class EventExtManager(models.Manager["EventExt"]):
|
||||||
def get_queryset(self) -> models.QuerySet["EventExt"]:
|
def get_queryset(self) -> models.QuerySet["EventExt"]:
|
||||||
return (
|
return super().get_queryset().annotate(duration=Sum("meeting_times__duration"))
|
||||||
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"))
|
|
||||||
|
|
||||||
|
|
||||||
class EventExt(Event):
|
class EventExt(Event):
|
||||||
@ -446,29 +440,18 @@ class EventExt(Event):
|
|||||||
verbose_name = "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):
|
class EventMeetingTime(models.Model):
|
||||||
objects = EventMeetingTimeManager()
|
|
||||||
|
|
||||||
event = models.ForeignKey(
|
event = models.ForeignKey(
|
||||||
EventExt, on_delete=models.CASCADE, related_name="meeting_times"
|
EventExt, on_delete=models.CASCADE, related_name="meeting_times"
|
||||||
)
|
)
|
||||||
start = models.DateTimeField()
|
start = models.DateTimeField()
|
||||||
end = models.DateTimeField()
|
end = models.DateTimeField()
|
||||||
|
|
||||||
# TODO: Should use generated field instead of manager, but this is
|
duration = models.GeneratedField(
|
||||||
# broken due to current Django bug, pending next release (> 5.0)
|
expression=F("end") - F("start"),
|
||||||
# ref: https://code.djangoproject.com/ticket/35019
|
output_field=models.DurationField(),
|
||||||
|
db_persist=False,
|
||||||
# duration = models.GeneratedField(
|
)
|
||||||
# expression=F("end") - F("start"),
|
|
||||||
# output_field=models.DurationField(),
|
|
||||||
# db_persist=False,
|
|
||||||
# )
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
|
Loading…
Reference in New Issue
Block a user