class DayArchiveView [source]
A day archive page showing all objects in a given day. Days in the future throw a 404 error, regardless of whether any objects exist for future days, unless you set allow_future to True.
Ancestors (MRO)
django.views.generic.list.MultipleObjectTemplateResponseMixindjango.views.generic.base.TemplateResponseMixindjango.views.generic.dates.BaseDayArchiveViewdjango.views.generic.dates.YearMixindjango.views.generic.dates.MonthMixindjango.views.generic.dates.DayMixindjango.views.generic.dates.BaseDateListViewdjango.views.generic.list.MultipleObjectMixindjango.views.generic.dates.DateMixindjango.views.generic.base.View
Context
In addition to the context provided by MultipleObjectMixin (via BaseDateListView), the template’s context will be:
-
day: Adateobject representing the given day. -
next_day: Adateobject representing the next day, according toallow_emptyandallow_future. -
previous_day: Adateobject representing the previous day, according toallow_emptyandallow_future. -
next_month: Adateobject representing the first day of the next month, according toallow_emptyandallow_future. -
previous_month: Adateobject representing the first day of the previous month, according toallow_emptyandallow_future.
Notes
- Uses a default
template_name_suffixof_archive_day.
Example myapp/views.py:
from django.views.generic.dates import DayArchiveView
from myapp.models import Article
class ArticleDayArchiveView(DayArchiveView):
queryset = Article.objects.all()
date_field = "pub_date"
allow_future = True
Example myapp/urls.py:
from django.conf.urls import url
from myapp.views import ArticleDayArchiveView
urlpatterns = [
# Example: /2012/nov/10/
url(r'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/$',
ArticleDayArchiveView.as_view(),
name="archive_day"),
]
Example myapp/article_archive_day.html:
<h1>{{ day }}</h1>
<ul>
{% for article in object_list %}
<li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li>
{% endfor %}
</ul>
<p>
{% if previous_day %}
Previous Day: {{ previous_day }}
{% endif %}
{% if previous_day and next_day %}--{% endif %}
{% if next_day %}
Next Day: {{ next_day }}
{% endif %}
</p>
Please login to continue.