summaryrefslogtreecommitdiff
path: root/docs/ref/class-based-views/generic-date-based.txt
blob: c6af23e421bae3cf32a3f0de0a6f47c74f909092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
==================
Generic date views
==================

.. module:: django.views.generic.dates

Date-based generic views, provided in :mod:`django.views.generic.dates`, are
views for displaying drilldown pages for date-based data.

ArchiveIndexView
----------------

.. class:: ArchiveIndexView

    A top-level index page showing the "latest" objects, by date. Objects with
    a date in the *future* are not included unless you set ``allow_future`` to
    ``True``.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.ArchiveIndexView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseArchiveIndexView`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`

    **Notes**

    * Uses a default ``context_object_name`` of ``latest``.
    * Uses a default ``template_name_suffix`` of ``_archive``.
    * Defaults to providing ``date_list`` by year, but this can be altered to
      month or day using the attribute ``date_list_period``. This also applies
      to all subclass views.

YearArchiveView
---------------

.. class:: YearArchiveView

    A yearly archive page showing all available months in a given year. Objects
    with a date in the *future* are not displayed unless you set
    ``allow_future`` to ``True``.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.YearArchiveView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseYearArchiveView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`

    .. attribute:: make_object_list

        A boolean specifying whether to retrieve the full list of objects for
        this year and pass those to the template. If ``True``, the list of
        objects will be made available to the context. If ``False``, the
        ``None`` queryset will be used as the object list. By default, this is
        ``False``.

    .. method:: get_make_object_list()

        Determine if an object list will be returned as part of the context.
        Returns :attr:`~YearArchiveView.make_object_list` by default.


    **Context**

    In addition to the context provided by
    :class:`django.views.generic.list.MultipleObjectMixin` (via
    :class:`django.views.generic.dates.BaseDateListView`), the template's
    context will be:

    * ``date_list``: A
      :meth:`DateQuerySet<django.db.models.query.QuerySet.dates>` object object
      containing all months that have objects available according to
      ``queryset``, represented as
      :class:`datetime.datetime<python:datetime.datetime>` objects, in
      ascending order.

    * ``year``: A :class:`~datetime.date` object
      representing the given year.

      .. versionchanged:: 1.5

      Previously, this returned a string.

    * ``next_year``: A :class:`~datetime.date` object
      representing the first day of the next year, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

      .. versionadded:: 1.5

    * ``previous_year``: A :class:`~datetime.date` object
      representing the first day of the previous year, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

      .. versionadded:: 1.5

    **Notes**

    * Uses a default ``template_name_suffix`` of ``_archive_year``.

MonthArchiveView
----------------

.. class:: MonthArchiveView

    A monthly archive page showing all objects in a given month. Objects with a
    date in the *future* are not displayed unless you set ``allow_future`` to
    ``True``.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.MonthArchiveView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseMonthArchiveView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.MonthMixin`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`

    **Context**

    In addition to the context provided by
    :class:`~django.views.generic.list.MultipleObjectMixin` (via
    :class:`~django.views.generic.dates.BaseDateListView`), the template's
    context will be:

    * ``date_list``: A
      :meth:`DateQuerySet<django.db.models.query.QuerySet.dates>` object
      containing all days that have objects available in the given month,
      according to ``queryset``, represented as
      :class:`datetime.datetime<python:datetime.datetime>` objects, in
      ascending order.

    * ``month``: A :class:`~datetime.date` object
      representing the given month.

    * ``next_month``: A :class:`~datetime.date` object
      representing the first day of the next month, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    * ``previous_month``: A :class:`~datetime.date` object
      representing the first day of the previous month, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    **Notes**

    * Uses a default ``template_name_suffix`` of ``_archive_month``.

WeekArchiveView
---------------

.. class:: WeekArchiveView

    A weekly archive page showing all objects in a given week. Objects with a
    date in the *future* are not displayed unless you set ``allow_future`` to
    ``True``.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.WeekArchiveView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseWeekArchiveView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.WeekMixin`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`

    **Context**

    In addition to the context provided by
    :class:`~django.views.generic.list.MultipleObjectMixin` (via
    :class:`~django.views.generic.dates.BaseDateListView`), the template's
    context will be:

    * ``week``: A :class:`~datetime.date` object
      representing the first day of the given week.

    * ``next_week``: A :class:`~datetime.date` object
      representing the first day of the next week, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    * ``previous_week``: A :class:`~datetime.date` object
      representing the first day of the previous week, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    **Notes**

    * Uses a default ``template_name_suffix`` of ``_archive_week``.

DayArchiveView
--------------

.. class:: DayArchiveView

    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)**

    * :class:`django.views.generic.dates.DayArchiveView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseDayArchiveView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.MonthMixin`
    * :class:`django.views.generic.dates.DayMixin`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`

    **Context**

    In addition to the context provided by
    :class:`~django.views.generic.list.MultipleObjectMixin` (via
    :class:`~django.views.generic.dates.BaseDateListView`), the template's
    context will be:

    * ``day``: A :class:`~datetime.date` object
      representing the given day.

    * ``next_day``: A :class:`~datetime.date` object
      representing the next day, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    * ``previous_day``: A :class:`~datetime.date` object
      representing the previous day, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    * ``next_month``: A :class:`~datetime.date` object
      representing the first day of the next month, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    * ``previous_month``: A :class:`~datetime.date` object
      representing the first day of the previous month, according to
      :attr:`~BaseDateListView.allow_empty` and
      :attr:`~DateMixin.allow_future`.

    **Notes**

    * Uses a default ``template_name_suffix`` of ``_archive_day``.

TodayArchiveView
----------------

.. class:: TodayArchiveView

    A day archive page showing all objects for *today*. This is exactly the
    same as :class:`django.views.generic.dates.DayArchiveView`, except today's
    date is used instead of the ``year``/``month``/``day`` arguments.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.TodayArchiveView`
    * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseTodayArchiveView`
    * :class:`django.views.generic.dates.BaseDayArchiveView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.MonthMixin`
    * :class:`django.views.generic.dates.DayMixin`
    * :class:`django.views.generic.dates.BaseDateListView`
    * :class:`django.views.generic.list.MultipleObjectMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.base.View`


DateDetailView
--------------

.. class:: DateDetailView

    A page representing an individual object. If the object has a date value in
    the future, the view will throw a 404 error by default, unless you set
    ``allow_future`` to ``True``.

    **Ancestors (MRO)**

    * :class:`django.views.generic.dates.DateDetailView`
    * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
    * :class:`django.views.generic.base.TemplateResponseMixin`
    * :class:`django.views.generic.dates.BaseDateDetailView`
    * :class:`django.views.generic.dates.YearMixin`
    * :class:`django.views.generic.dates.MonthMixin`
    * :class:`django.views.generic.dates.DayMixin`
    * :class:`django.views.generic.dates.DateMixin`
    * :class:`django.views.generic.detail.BaseDetailView`
    * :class:`django.views.generic.detail.SingleObjectMixin`
    * :class:`django.views.generic.base.View`

.. note::

    All of the generic views listed above have matching ``Base`` views that
    only differ in that the they do not include the
    :class:`~django.views.generic.detail.SingleObjectTemplateResponseMixin`:

    .. class:: BaseArchiveIndexView

    .. class:: BaseYearArchiveView

    .. class:: BaseMonthArchiveView

    .. class:: BaseWeekArchiveView

    .. class:: BaseDayArchiveView

    .. class:: BaseTodayArchiveView

    .. class:: BaseDateDetailView