Quantcast
Channel: Django: Create a variable in template - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Django: Create a variable in template

$
0
0

I have a list of values I want to display in a template of django.

The list is more or less like this:

199801 string1199802 string2199904 string3200003 string4200011 string5

where the first column is a date in the form YYYYMM and the second is a generic string

the list is ordered by date desc

What I want to create is a list of stringx grouped by yearsomething like this:

1998 string1, string21999 string32000 string4, string5

I gave a look to the documentation and I think the only thing I need is a way to create a variable where to store the "last year" I printed, so I can do something like:

if current_value.year != last_year     #create a new row with the new year and the stringelse     #append the current string to the previous one

I think the only way I found is to write a custom templatetag and let it store the variable and the value... but before starting to write code I would like to know if there is a simpler way!


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images