I have a TimeField() in my django models. I want to convert the sum of the record of this to hours.
Here's the actual code in my view:
hours_week_decimal = Timesheet.objects.filter(owner = request.user.pk, week = datetime.datetime.now().isocalendar()[1]).aggregate(total=Sum('working_hour')) # this method return a dict of decimal
total_hours_week = convertDecimalToHours(hours_week_decimal)
and the related function:
def convertDecimalToHours(times):
total_time = 0
for k, v in times.items():
total_time += int(v)
print("type: {} - value: {}".format(type(total_time), total_time))
This returned me:
type: int - value: 166000
I have two hours:
Monday (08:30) and Tuesday(08:30)
It must have returned me "17:00"
Hope you can help me in solving this problem :)