generic-date-based.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. * ``next_year``: A :class:`~datetime.date` object
  67. representing the first day of the next year, according to
  68. :attr:`~BaseDateListView.allow_empty` and
  69. :attr:`~DateMixin.allow_future`.
  70. * ``previous_year``: A :class:`~datetime.date` object
  71. representing the first day of the previous year, according to
  72. :attr:`~BaseDateListView.allow_empty` and
  73. :attr:`~DateMixin.allow_future`.
  74. **Notes**
  75. * Uses a default ``template_name_suffix`` of ``_archive_year``.
  76. MonthArchiveView
  77. ----------------
  78. .. class:: MonthArchiveView
  79. A monthly archive page showing all objects in a given month. Objects with a
  80. date in the *future* are not displayed unless you set ``allow_future`` to
  81. ``True``.
  82. **Ancestors (MRO)**
  83. * :class:`django.views.generic.dates.MonthArchiveView`
  84. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  85. * :class:`django.views.generic.base.TemplateResponseMixin`
  86. * :class:`django.views.generic.dates.BaseMonthArchiveView`
  87. * :class:`django.views.generic.dates.YearMixin`
  88. * :class:`django.views.generic.dates.MonthMixin`
  89. * :class:`django.views.generic.dates.BaseDateListView`
  90. * :class:`django.views.generic.list.MultipleObjectMixin`
  91. * :class:`django.views.generic.dates.DateMixin`
  92. * :class:`django.views.generic.base.View`
  93. **Context**
  94. In addition to the context provided by
  95. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  96. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  97. context will be:
  98. * ``date_list``: A
  99. :meth:`DateQuerySet<django.db.models.query.QuerySet.dates>` object
  100. containing all days that have objects available in the given month,
  101. according to ``queryset``, represented as
  102. :class:`datetime.datetime<python:datetime.datetime>` objects, in
  103. ascending order.
  104. * ``month``: A :class:`~datetime.date` object
  105. representing the given month.
  106. * ``next_month``: A :class:`~datetime.date` object
  107. representing the first day of the next month, according to
  108. :attr:`~BaseDateListView.allow_empty` and
  109. :attr:`~DateMixin.allow_future`.
  110. * ``previous_month``: A :class:`~datetime.date` object
  111. representing the first day of the previous month, according to
  112. :attr:`~BaseDateListView.allow_empty` and
  113. :attr:`~DateMixin.allow_future`.
  114. **Notes**
  115. * Uses a default ``template_name_suffix`` of ``_archive_month``.
  116. WeekArchiveView
  117. ---------------
  118. .. class:: WeekArchiveView
  119. A weekly archive page showing all objects in a given week. Objects with a
  120. date in the *future* are not displayed unless you set ``allow_future`` to
  121. ``True``.
  122. **Ancestors (MRO)**
  123. * :class:`django.views.generic.dates.WeekArchiveView`
  124. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  125. * :class:`django.views.generic.base.TemplateResponseMixin`
  126. * :class:`django.views.generic.dates.BaseWeekArchiveView`
  127. * :class:`django.views.generic.dates.YearMixin`
  128. * :class:`django.views.generic.dates.WeekMixin`
  129. * :class:`django.views.generic.dates.BaseDateListView`
  130. * :class:`django.views.generic.list.MultipleObjectMixin`
  131. * :class:`django.views.generic.dates.DateMixin`
  132. * :class:`django.views.generic.base.View`
  133. **Context**
  134. In addition to the context provided by
  135. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  136. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  137. context will be:
  138. * ``week``: A :class:`~datetime.date` object
  139. representing the first day of the given week.
  140. * ``next_week``: A :class:`~datetime.date` object
  141. representing the first day of the next week, according to
  142. :attr:`~BaseDateListView.allow_empty` and
  143. :attr:`~DateMixin.allow_future`.
  144. * ``previous_week``: A :class:`~datetime.date` object
  145. representing the first day of the previous week, according to
  146. :attr:`~BaseDateListView.allow_empty` and
  147. :attr:`~DateMixin.allow_future`.
  148. **Notes**
  149. * Uses a default ``template_name_suffix`` of ``_archive_week``.
  150. DayArchiveView
  151. --------------
  152. .. class:: DayArchiveView
  153. A day archive page showing all objects in a given day. Days in the future
  154. throw a 404 error, regardless of whether any objects exist for future days,
  155. unless you set ``allow_future`` to ``True``.
  156. **Ancestors (MRO)**
  157. * :class:`django.views.generic.dates.DayArchiveView`
  158. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  159. * :class:`django.views.generic.base.TemplateResponseMixin`
  160. * :class:`django.views.generic.dates.BaseDayArchiveView`
  161. * :class:`django.views.generic.dates.YearMixin`
  162. * :class:`django.views.generic.dates.MonthMixin`
  163. * :class:`django.views.generic.dates.DayMixin`
  164. * :class:`django.views.generic.dates.BaseDateListView`
  165. * :class:`django.views.generic.list.MultipleObjectMixin`
  166. * :class:`django.views.generic.dates.DateMixin`
  167. * :class:`django.views.generic.base.View`
  168. **Context**
  169. In addition to the context provided by
  170. :class:`~django.views.generic.list.MultipleObjectMixin` (via
  171. :class:`~django.views.generic.dates.BaseDateListView`), the template's
  172. context will be:
  173. * ``day``: A :class:`~datetime.date` object
  174. representing the given day.
  175. * ``next_day``: A :class:`~datetime.date` object
  176. representing the next day, according to
  177. :attr:`~BaseDateListView.allow_empty` and
  178. :attr:`~DateMixin.allow_future`.
  179. * ``previous_day``: A :class:`~datetime.date` object
  180. representing the previous day, according to
  181. :attr:`~BaseDateListView.allow_empty` and
  182. :attr:`~DateMixin.allow_future`.
  183. * ``next_month``: A :class:`~datetime.date` object
  184. representing the first day of the next month, according to
  185. :attr:`~BaseDateListView.allow_empty` and
  186. :attr:`~DateMixin.allow_future`.
  187. * ``previous_month``: A :class:`~datetime.date` object
  188. representing the first day of the previous month, according to
  189. :attr:`~BaseDateListView.allow_empty` and
  190. :attr:`~DateMixin.allow_future`.
  191. **Notes**
  192. * Uses a default ``template_name_suffix`` of ``_archive_day``.
  193. TodayArchiveView
  194. ----------------
  195. .. class:: TodayArchiveView
  196. A day archive page showing all objects for *today*. This is exactly the
  197. same as :class:`django.views.generic.dates.DayArchiveView`, except today's
  198. date is used instead of the ``year``/``month``/``day`` arguments.
  199. **Ancestors (MRO)**
  200. * :class:`django.views.generic.dates.TodayArchiveView`
  201. * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
  202. * :class:`django.views.generic.base.TemplateResponseMixin`
  203. * :class:`django.views.generic.dates.BaseTodayArchiveView`
  204. * :class:`django.views.generic.dates.BaseDayArchiveView`
  205. * :class:`django.views.generic.dates.YearMixin`
  206. * :class:`django.views.generic.dates.MonthMixin`
  207. * :class:`django.views.generic.dates.DayMixin`
  208. * :class:`django.views.generic.dates.BaseDateListView`
  209. * :class:`django.views.generic.list.MultipleObjectMixin`
  210. * :class:`django.views.generic.dates.DateMixin`
  211. * :class:`django.views.generic.base.View`
  212. DateDetailView
  213. --------------
  214. .. class:: DateDetailView
  215. A page representing an individual object. If the object has a date value in
  216. the future, the view will throw a 404 error by default, unless you set
  217. ``allow_future`` to ``True``.
  218. **Ancestors (MRO)**
  219. * :class:`django.views.generic.dates.DateDetailView`
  220. * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
  221. * :class:`django.views.generic.base.TemplateResponseMixin`
  222. * :class:`django.views.generic.dates.BaseDateDetailView`
  223. * :class:`django.views.generic.dates.YearMixin`
  224. * :class:`django.views.generic.dates.MonthMixin`
  225. * :class:`django.views.generic.dates.DayMixin`
  226. * :class:`django.views.generic.dates.DateMixin`
  227. * :class:`django.views.generic.detail.BaseDetailView`
  228. * :class:`django.views.generic.detail.SingleObjectMixin`
  229. * :class:`django.views.generic.base.View`
  230. .. note::
  231. All of the generic views listed above have matching ``Base`` views that
  232. only differ in that the they do not include the
  233. :class:`~django.views.generic.detail.SingleObjectTemplateResponseMixin`:
  234. .. class:: BaseArchiveIndexView
  235. .. class:: BaseYearArchiveView
  236. .. class:: BaseMonthArchiveView
  237. .. class:: BaseWeekArchiveView
  238. .. class:: BaseDayArchiveView
  239. .. class:: BaseTodayArchiveView
  240. .. class:: BaseDateDetailView