Hello Django-users,

Actually it's more of a basic Python problem than a Django problem.
I'll try to be brief:

In the view, I'm looping through my posts as such:
---
def archive(request):
    years = Post.objects.dates('pub_date', 'year')
    for year in years:
        print year.year
        months = Post.objects.filter(pub_date__year=year.year).dates
('pub_date', 'month')
        for month in months:
            print month.month

return render_to_ etcetera........
---

I don't know how I can dynamically create a list/array/dict/tuple
through which I can loop in the template like this:
---
{% for y in years %}
    <h2>{{ y.year }}</h2>
    {% for m in y.months %}
        <h3>{{ m.month }}</h3>
        {% for post in m.post.all %}
            <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
{% if not forloop.last %},{% endif %}
        {% endfor %}
    {% endfor %}
{% endfor %}
---

Or is there a better way to generate a full archive page (per year,
per month)?

Thanks,
Gijs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to