generic-date-based.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. ==================
  2. Generic date views
  3. ==================
  4. .. module:: django.views.generic.dates
  5. Date-based generic views, provided in :mod:`django.views.generic.dates`, are
  6. views for displaying drilldown pages for date-based data.
  7. ArchiveIndexView
  8. ----------------
  9. .. class:: ArchiveIndexView
  10. A top-level index page showing the "latest" objects, by date. Objects with
  11. a date in the *future* are not included unless you set ``allow_future`` to
  12. ``True``.
  13. **Ancestors (MRO)**
  14. * :class:`django.views.generic.dates.ArchiveIndexView`
  15. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  16. * :class:`django.views.generic.base.TemplateResponseMixin`
  17. * :class:`django.views.generic.dates.BaseArchiveIndexView`
  18. * :class:`django.views.generic.dates.BaseDateListView`
  19. * :class:`django.views.generic.list.MultipleObjectMixin`
  20. * :class:`django.views.generic.dates.DateMixin`
  21. * :class:`django.views.generic.base.View`
  22. **Notes**
  23. * Uses a default ``context_object_name`` of ``latest``.
  24. * Uses a default ``template_name_suffix`` of ``_archive``.
  25. * Defaults to providing ``date_list`` by year, but this can be altered to
  26. month or day using the attribute ``date_list_period``. This also applies
  27. to all subclass views.
  28. YearArchiveView
  29. ---------------
  30. .. class:: YearArchiveView
  31. A yearly archive page showing all available months in a given year. Objects
  32. with a date in the *future* are not displayed unless you set
  33. ``allow_future`` to ``True``.
  34. **Ancestors (MRO)**
  35. * :class:`django.views.generic.dates.YearArchiveView`
  36. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  37. * :class:`django.views.generic.base.TemplateResponseMixin`
  38. * :class:`django.views.generic.dates.BaseYearArchiveView`
  39. * :class:`django.views.generic.dates.YearMixin`
  40. * :class:`django.views.generic.dates.BaseDateListView`
  41. * :class:`django.views.generic.list.MultipleObjectMixin`
  42. * :class:`django.views.generic.dates.DateMixin`
  43. * :class:`django.views.generic.base.View`
  44. .. attribute:: make_object_list
  45. A boolean specifying whether to retrieve the full list of objects for
  46. this year and pass those to the template. If ``True``, the list of
  47. objects will be made available to the context. If ``False``, the
  48. ``None`` queryset will be used as the object list. By default, this is
  49. ``False``.
  50. .. method:: get_make_object_list()
  51. Determine if an object list will be returned as part of the context.
  52. Returns :attr:`~YearArchiveView.make_object_list` by default.
  53. **Context**
  54. In addition to the context provided by
  55. :class:`django.views.generic.list.MultipleObjectMixin` (via
  56. :class:`django.views.generic.dates.BaseDateListView`), the template's
  57. context will be:
  58. * ``date_list``: A
  59. :meth:`DateQuerySet<django.db.models.query.QuerySet.dates>` object object
  60. containing all months that have objects available according to
  61. ``queryset``, represented as
  62. :class:`datetime.datetime<python:datetime.datetime>` objects, in
  63. ascending order.
  64. * ``year``: A :class:`~datetime.date` object
  65. representing the given year.
  66. .. versionchanged:: 1.5
  67. Previously, this returned a string.
  68. * ``next_year``: A :class:`~datetime.date` object
  69. representing the first day of the next year, according to
  70. :attr:`~BaseDateListView.allow_empty` and
  71. :attr:`~DateMixin.allow_future`.
  72. .. versionadded:: 1.5
  73. * ``previous_year``: A :class:`~datetime.date` object
  74. representing the first day of the previous year, according to
  75. :attr:`~BaseDateListView.allow_empty` and
  76. :attr:`~DateMixin.allow_future`.
  77. .. versionadded:: 1.5
  78. **Notes**
  79. * Uses a default ``template_name_suffix`` of ``_archive_year``.
  80. MonthArchiveView
  81. ----------------
  82. .. class:: MonthArchiveView
  83. A monthly archive page showing all objects in a given month. Objects with a
  84. date in the *future* are not displayed unless you set ``allow_future`` to
  85. ``True``.
  86. **Ancestors (MRO)**
  87. * :class:`django.views.generic.dates.MonthArchiveView`
  88. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  89. * :class:`django.views.generic.base.TemplateResponseMixin`
  90. * :class:`django.views.generic.dates.BaseMonthArchiveView`
  91. * :class:`django.views.generic.dates.YearMixin`
  92. * :class:`django.views.generic.dates.MonthMixin`
  93. * :class:`django.views.generic.dates.BaseDateListView`
  94. * :class:`django.views.generic.list.MultipleObjectMixin`
  95. * :class:`django.views.generic.dates.DateMixin`
  96. * :class:`django.views.generic.base.View`
  97. **Context**
  98. In addition to the context provided by
  99. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  100. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  101. context will be:
  102. * ``date_list``: A
  103. :meth:`DateQuerySet<django.db.models.query.QuerySet.dates>` object
  104. containing all days that have objects available in the given month,
  105. according to ``queryset``, represented as
  106. :class:`datetime.datetime<python:datetime.datetime>` objects, in
  107. ascending order.
  108. * ``month``: A :class:`~datetime.date` object
  109. representing the given month.
  110. * ``next_month``: A :class:`~datetime.date` object
  111. representing the first day of the next month, according to
  112. :attr:`~BaseDateListView.allow_empty` and
  113. :attr:`~DateMixin.allow_future`.
  114. * ``previous_month``: A :class:`~datetime.date` object
  115. representing the first day of the previous month, according to
  116. :attr:`~BaseDateListView.allow_empty` and
  117. :attr:`~DateMixin.allow_future`.
  118. **Notes**
  119. * Uses a default ``template_name_suffix`` of ``_archive_month``.
  120. WeekArchiveView
  121. ---------------
  122. .. class:: WeekArchiveView
  123. A weekly archive page showing all objects in a given week. Objects with a
  124. date in the *future* are not displayed unless you set ``allow_future`` to
  125. ``True``.
  126. **Ancestors (MRO)**
  127. * :class:`django.views.generic.dates.WeekArchiveView`
  128. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  129. * :class:`django.views.generic.base.TemplateResponseMixin`
  130. * :class:`django.views.generic.dates.BaseWeekArchiveView`
  131. * :class:`django.views.generic.dates.YearMixin`
  132. * :class:`django.views.generic.dates.WeekMixin`
  133. * :class:`django.views.generic.dates.BaseDateListView`
  134. * :class:`django.views.generic.list.MultipleObjectMixin`
  135. * :class:`django.views.generic.dates.DateMixin`
  136. * :class:`django.views.generic.base.View`
  137. **Context**
  138. In addition to the context provided by
  139. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  140. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  141. context will be:
  142. * ``week``: A :class:`~datetime.date` object
  143. representing the first day of the given week.
  144. * ``next_week``: A :class:`~datetime.date` object
  145. representing the first day of the next week, according to
  146. :attr:`~BaseDateListView.allow_empty` and
  147. :attr:`~DateMixin.allow_future`.
  148. * ``previous_week``: A :class:`~datetime.date` object
  149. representing the first day of the previous week, according to
  150. :attr:`~BaseDateListView.allow_empty` and
  151. :attr:`~DateMixin.allow_future`.
  152. **Notes**
  153. * Uses a default ``template_name_suffix`` of ``_archive_week``.
  154. DayArchiveView
  155. --------------
  156. .. class:: DayArchiveView
  157. A day archive page showing all objects in a given day. Days in the future
  158. throw a 404 error, regardless of whether any objects exist for future days,
  159. unless you set ``allow_future`` to ``True``.
  160. **Ancestors (MRO)**
  161. * :class:`django.views.generic.dates.DayArchiveView`
  162. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  163. * :class:`django.views.generic.base.TemplateResponseMixin`
  164. * :class:`django.views.generic.dates.BaseDayArchiveView`
  165. * :class:`django.views.generic.dates.YearMixin`
  166. * :class:`django.views.generic.dates.MonthMixin`
  167. * :class:`django.views.generic.dates.DayMixin`
  168. * :class:`django.views.generic.dates.BaseDateListView`
  169. * :class:`django.views.generic.list.MultipleObjectMixin`
  170. * :class:`django.views.generic.dates.DateMixin`
  171. * :class:`django.views.generic.base.View`
  172. **Context**
  173. In addition to the context provided by
  174. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  175. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  176. context will be:
  177. * ``day``: A :class:`~datetime.date` object
  178. representing the given day.
  179. * ``next_day``: A :class:`~datetime.date` object
  180. representing the next day, according to
  181. :attr:`~BaseDateListView.allow_empty` and
  182. :attr:`~DateMixin.allow_future`.
  183. * ``previous_day``: A :class:`~datetime.date` object
  184. representing the previous day, according to
  185. :attr:`~BaseDateListView.allow_empty` and
  186. :attr:`~DateMixin.allow_future`.
  187. * ``next_month``: A :class:`~datetime.date` object
  188. representing the first day of the next month, according to
  189. :attr:`~BaseDateListView.allow_empty` and
  190. :attr:`~DateMixin.allow_future`.
  191. * ``previous_month``: A :class:`~datetime.date` object
  192. representing the first day of the previous month, according to
  193. :attr:`~BaseDateListView.allow_empty` and
  194. :attr:`~DateMixin.allow_future`.
  195. **Notes**
  196. * Uses a default ``template_name_suffix`` of ``_archive_day``.
  197. TodayArchiveView
  198. ----------------
  199. .. class:: TodayArchiveView
  200. A day archive page showing all objects for *today*. This is exactly the
  201. same as :class:`django.views.generic.dates.DayArchiveView`, except today's
  202. date is used instead of the ``year``/``month``/``day`` arguments.
  203. **Ancestors (MRO)**
  204. * :class:`django.views.generic.dates.TodayArchiveView`
  205. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  206. * :class:`django.views.generic.base.TemplateResponseMixin`
  207. * :class:`django.views.generic.dates.BaseTodayArchiveView`
  208. * :class:`django.views.generic.dates.BaseDayArchiveView`
  209. * :class:`django.views.generic.dates.YearMixin`
  210. * :class:`django.views.generic.dates.MonthMixin`
  211. * :class:`django.views.generic.dates.DayMixin`
  212. * :class:`django.views.generic.dates.BaseDateListView`
  213. * :class:`django.views.generic.list.MultipleObjectMixin`
  214. * :class:`django.views.generic.dates.DateMixin`
  215. * :class:`django.views.generic.base.View`
  216. DateDetailView
  217. --------------
  218. .. class:: DateDetailView
  219. A page representing an individual object. If the object has a date value in
  220. the future, the view will throw a 404 error by default, unless you set
  221. ``allow_future`` to ``True``.
  222. **Ancestors (MRO)**
  223. * :class:`django.views.generic.dates.DateDetailView`
  224. * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
  225. * :class:`django.views.generic.base.TemplateResponseMixin`
  226. * :class:`django.views.generic.dates.BaseDateDetailView`
  227. * :class:`django.views.generic.dates.YearMixin`
  228. * :class:`django.views.generic.dates.MonthMixin`
  229. * :class:`django.views.generic.dates.DayMixin`
  230. * :class:`django.views.generic.dates.DateMixin`
  231. * :class:`django.views.generic.detail.BaseDetailView`
  232. * :class:`django.views.generic.detail.SingleObjectMixin`
  233. * :class:`django.views.generic.base.View`
  234. .. note::
  235. All of the generic views listed above have matching ``Base`` views that
  236. only differ in that the they do not include the
  237. :class:`~django.views.generic.detail.SingleObjectTemplateResponseMixin`:
  238. .. class:: BaseArchiveIndexView
  239. .. class:: BaseYearArchiveView
  240. .. class:: BaseMonthArchiveView
  241. .. class:: BaseWeekArchiveView
  242. .. class:: BaseDayArchiveView
  243. .. class:: BaseTodayArchiveView
  244. .. class:: BaseDateDetailView