I am trying to sum the hours user spent per day. I wanted to convert this into whole number or decimal (e.g. 2, 6.5) hrs, to easily plot this to my chart. But the result of below code is in this format HH:mm:ss. Any one can help me with this?
day = Clocking.objects.filter(clockout__isnull=False, user=nid).annotate(date=TruncDate('clockin'))
.values('date').annotate(total=Sum(F('clockout') - F('clockin'))).values('total')
Here is my models.py
class Clocking(models.Model):
user= models.ForeignKey('User', models.DO_NOTHING)
clockin = models.DateTimeField()
clockout = models.DateTimeField(null=True)
New contributor
zheni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.