I created the following model:
class Timesheet(models.Model):
date = models.DateField(auto_now=False, auto_now_add=False, verbose_name="Data")
entry = models.TimeField(auto_now=False, auto_now_add=False, verbose_name="Hora Entrada")
lunch = models.TimeField(auto_now=False, auto_now_add=False, null=True, blank=True, verbose_name="Início do Almoço")
lunch_end = models.TimeField(auto_now=False, auto_now_add=False, null=True, blank=True, verbose_name="Fim do Almoço")
out = models.TimeField(auto_now=False, auto_now_add=False, verbose_name="Hora de Saída")
This is then returned in a table, that has an extra field called "Total Hours", in which I need to calculate the total worked hours. Each entry refers to the same day.
And I have the following view:
def timesheet(request):
c = Timesheet.objects.all()
context = {'c': c}
return render(request, "tracker/timesheet.html", context)
The calculation I need to do is: (out - entry) - (lunch_end - lunch)
.
How can I achieve this?