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

200
Views
¿Cómo puedo invertir el conteo de un conjunto de consultas en un bucle for?

Mi código de plantilla es este

 {% for announcement in announcements %} <tr> <td>{{ count }}</td> <td>{{ announcement.title }}</td> <td>{{ announcement.user.profile.name }}</td> <td>{{ announcement.modified }}</td> </tr> {% endfor %}

Quiero contar hacia atrás desde la length of queryset hasta 1.

¿Cómo puedo hacer eso?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Hay un contador inverso llamado forloop.revcounter que cuenta desde la longitud del conjunto de consultas hasta 1.

 {% for announcement in announcements %} <tr> <td>{{ forloop.revcounter }}</td> <td>{{ announcement.title }}</td> <td>{{ announcement.user.profile.name }}</td> <td>{{ announcement.modified }}</td> </tr> {% endfor %}

Hay cero ( forloop.revcounter0 ) y 1 indexado ( forloop.revcounter ) conteo inverso disponible.

Plantilla de Django "para" documentación .

over 4 years ago · Santiago Trujillo Report

0

Si está buscando un contador que comience desde 1 y se incremente durante el ciclo, debe usar forloop.counter de django

 {% for announcement in announcements %} <tr> <td>{{ forloop.counter }}</td> <td>{{ announcement.title }}</td> <td>{{ announcement.user.profile.name }}</td> <td>{{ announcement.modified }}</td> </tr> {% endfor %}
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!