[patch] Add reverse counter variables to template "for loops"
I had a need to iterate backwards through the counter (i.e. 24,23,22,21...1) while displaying the items in a list in the proper order. I propose the addition of forloop.counterr and forloop.counter0r variables to complement forloop.counter and forloop.counter0.
It's a simple patch and I've inlcluded it here:
--- django/core/defaulttags.py (revision 453)
+++ django/core/defaulttags.py (working copy)
@@ -97,6 +97,8 @@
# shortcuts for current loop iteration number
'counter0': i,
'counter': i+1,
+ 'counterr': len(values)-i,
+ 'counter0r' : len(values)-i-1,
# boolean values designating first and last times through loop
'first': (i == 0),
'last': (i == len_values - 1),
Change History
(5)
Summary: |
[patch] Add reverse counter variables to template for loops → [patch] Add reverse counter variables to template "for loops"
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Component: |
Template system → django-admin.py
|
priority: |
normal → high
|
Severity: |
normal → major
|
Summary: |
[patch] Add reverse counter variables to template "for loops" → [patch] Add reverse counter variables to template "for loops"
|
Type: |
enhancement → defect
|
Version: |
→ 0.9
|
I think it should be named "revcounter" and "revcounter0" or maybe "invcounter". Just one letter of difference between the two would be prone to mistakes.