get_make_object_list()
Determine if an object list will be returned as part of the context. Returns make_object_list
by default.
Context
In addition to the context provided by django.views.generic.list.MultipleObjectMixin
(via django.views.generic.dates.BaseDateListView
), the template’s context will be:
-
date_list
: AQuerySet
object containing all months that have objects available according toqueryset
, represented asdatetime.datetime
objects, in ascending order. -
year
: Adate
object representing the given year. -
next_year
: Adate
object representing the first day of the next year, according toallow_empty
andallow_future
. -
previous_year
: Adate
object representing the first day of the previous year, according toallow_empty
andallow_future
.
Notes
- Uses a default
template_name_suffix
of_archive_year
.
Example myapp/views.py:
from django.views.generic.dates import YearArchiveView from myapp.models import Article class ArticleYearArchiveView(YearArchiveView): queryset = Article.objects.all() date_field = "pub_date" make_object_list = True allow_future = True
Example myapp/urls.py:
from django.conf.urls import url from myapp.views import ArticleYearArchiveView urlpatterns = [ url(r'^(?P<year>[0-9]{4})/$', ArticleYearArchiveView.as_view(), name="article_year_archive"), ]
Example myapp/article_archive_year.html:
<ul> {% for date in date_list %} <li>{{ date|date }}</li> {% endfor %} </ul> <div> <h1>All Articles for {{ year|date:"Y" }}</h1> {% for obj in object_list %} <p> {{ obj.title }} - {{ obj.pub_date|date:"F j, Y" }} </p> {% endfor %} </div>
Please login to continue.