« Semantic Review | Main | You lost me right about there »

Django Generic View: archive_monthdays

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 %}
          <a href="{{ date|date:"d"|lower }}/">
             {{ date|date:"D" }} {{ date|date:"d" }}</a>
	{% endfor %}
    {% endblock %}	

November 23, 2006 11:03 PM


Post a comment

(you may use HTML tags for style)

Remember Me?

Trackback Pings

TrackBack URL for this entry: