Skip to content

Commit

Permalink
Another method to prioritize precalculated duration
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow committed Nov 30, 2023
1 parent 68c207f commit 65135bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def duration_label(self) -> str:
If duration was populated by a query annotation, use that
otherwise call the duration() method to calculate it.
"""
duration = self.duration if isinstance(self.duration, datetime.timedelta) else self.duration()
duration = self.duration() if callable(self.duration) else self.duration
return ami.utils.dates.format_timedelta(duration)

# These are now loaded with annotations in EventViewSet
Expand Down Expand Up @@ -1475,7 +1475,7 @@ def duration_label(self) -> str | None:
If duration has been calculated by a query annotation, use that value
otherwise call the duration() method to calculate it.
"""
duration = self.duration if isinstance(self.duration, datetime.timedelta) else self.duration()
duration = self.duration() if callable(self.duration) else self.duration
return ami.utils.dates.format_timedelta(duration)

def detection_images(self, limit=None):
Expand Down

0 comments on commit 65135bc

Please sign in to comment.