I am trying to display the elapsed time during a race.
class results(models.Model):
race_id = models.ForeignKey(Race, on_delete=models.CASCADE)
runner_id = models.ForeignKey(Runner, on_delete=models.CASCADE)
race_start = models.DateTimeField()
race_finish = models.DateTimeField(blank=True, null=True)
obs = models.TextField(blank=True)
def __str__(self):
return self.race_id.race_cod+" - "+self.runner_id.name
class Meta:
verbose_name_plural = "Results"
Looking here I have found the following guides:
Django model elapsed time between two DateTimeFields
Django: What's the best field type to represent time elapsed?
Unfortunately, the solution presented there seems a little bit complex.
I also have found this workaround in the .html
view page
<div class="info-box-content">
<span class="info-box-number">Time - {{ results.race_finish|timesince:results.race_start }}</span>
</div>
the issue with this one is that everything over 24 hours came as x days, yy hours - while my need is to display the duration as HH:mm
Any hints here?