generic-date-based.txt 11 KB

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