I am creating a project in Django, my model has two fields where I add up the hours of a given activity, in my view I make a query where I sum the total hours of activities per student but I want to add duracion_dft with duracion_dfp, ¿ How can I do that?
Model
class Actividad(models.Model):
duracion_dft = models.DurationField('Duración horas teóricas HH:MM:SS', default=datetime.timedelta(minutes=0))
duracion_dfp = models.DurationField('Duración horas prácticas HH:MM:SS', default=datetime.timedelta(minutes=0))
Vista
def curso(request, id=id):
consulta = Estudiante.objects.filter(idCurso=id).annotate(teorica=Sum('actividad__duracion_dft'), presencial=Sum('actividad__duracion_dfp'), total=Sum(F('actividad__duracion_dft')+F('actividad__duracion_dfp')))
Result
- theory = 0:00:00
- face-to-face = 2:50:00
- total = 0: 00: 00.000002