Django Generic View: archive_monthdays
November 23, 2006 |
co.mments
Django's generic views have an archive_month view , which defaults to listing all the objects found in that month. If you have a high volume of things to show you might not want to render them all on a single page. So instead it might be handy to break the month down by days, in the same way archive_year breaks down by month. Here's a generic view that does that: http://dehora.net/code/django/archive_monthdays.py
Essentially it's a cloned version of the archive_month view, with the following changes:
- make_object_list: the same arg as found on archive_year, make list of objects published in the given month if True; defaults to False
- "year" passed as a str to the template context
- "days": passed as a list of dates to the template context
and here's a simple archive_monthdays template:
{% extends "base_site.html" %}
{% block content %}
<h2>{{ month|date:"F" }} {{ year }} Archive</h2>
<ul class="linklist">
{% for date in days %}
<li>
<a href="{{ date|date:"d"|lower }}/">
{{ date|date:"D" }} {{ date|date:"d" }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
November 23, 2006 11:03 PM
Comments
Post a comment
Trackback Pings
TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/2001