Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
Totales incrementales en Django Model

Tengo una tabla como la siguiente: Tabla de ejemplo

y tengo un modelo como

 class Hours(models.Model): name = model.Charfield(max_length =200) hours = DecimalField(max_digits = 6, decimal_places=2) def total_hours(self): queryset = Hours.objects.aggregate(total_hours=models.Sum('hours')) return queryset['total_hours']

ahora, cuando ejecuto el código, obtengo que todos los registros tienen hasta 37 en lugar de que tengan un total acumulado.

¿Dónde perdí un paso?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cada vez que llama a total_hours obtiene la suma de horas sobre todos los objetos Hours. Necesitarías algo como:

 Hours.objects.filter(id__lte=self.id).aggregate(total_hours=models.Sum('hours'))

para un total acumulado

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!