generic-date-based.txt 11 KB

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