1. ==================
    
  2. Generic date views
    
  3. ==================
    
  4. 
    
  5. .. module:: django.views.generic.dates
    
  6. 
    
  7. Date-based generic views, provided in :mod:`django.views.generic.dates`, are
    
  8. views for displaying drilldown pages for date-based data.
    
  9. 
    
  10. .. note::
    
  11. 
    
  12.     Some of the examples on this page assume that an ``Article`` model has been
    
  13.     defined as follows in ``myapp/models.py``::
    
  14. 
    
  15.         from django.db import models
    
  16.         from django.urls import reverse
    
  17. 
    
  18.         class Article(models.Model):
    
  19.             title = models.CharField(max_length=200)
    
  20.             pub_date = models.DateField()
    
  21. 
    
  22.             def get_absolute_url(self):
    
  23.                 return reverse('article-detail', kwargs={'pk': self.pk})
    
  24. 
    
  25. ``ArchiveIndexView``
    
  26. ====================
    
  27. 
    
  28. .. class:: ArchiveIndexView
    
  29. 
    
  30.     A top-level index page showing the "latest" objects, by date. Objects with
    
  31.     a date in the *future* are not included unless you set ``allow_future`` to
    
  32.     ``True``.
    
  33. 
    
  34.     **Ancestors (MRO)**
    
  35. 
    
  36.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  37.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  38.     * :class:`django.views.generic.dates.BaseArchiveIndexView`
    
  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. 
    
  44.     **Context**
    
  45. 
    
  46.     In addition to the context provided by
    
  47.     :class:`django.views.generic.list.MultipleObjectMixin` (via
    
  48.     :class:`django.views.generic.dates.BaseDateListView`), the template's
    
  49.     context will be:
    
  50. 
    
  51.     * ``date_list``: A :meth:`QuerySet <django.db.models.query.QuerySet.dates>`
    
  52.       object containing all years that have objects available according to
    
  53.       ``queryset``, represented as :class:`datetime.datetime` objects, in
    
  54.       descending order.
    
  55. 
    
  56.     **Notes**
    
  57. 
    
  58.     * Uses a default ``context_object_name`` of ``latest``.
    
  59.     * Uses a default ``template_name_suffix`` of ``_archive``.
    
  60.     * Defaults to providing ``date_list`` by year, but this can be altered to
    
  61.       month or day using the attribute ``date_list_period``. This also applies
    
  62.       to all subclass views.
    
  63. 
    
  64.     **Example myapp/urls.py**::
    
  65. 
    
  66.         from django.urls import path
    
  67.         from django.views.generic.dates import ArchiveIndexView
    
  68. 
    
  69.         from myapp.models import Article
    
  70. 
    
  71.         urlpatterns = [
    
  72.             path('archive/',
    
  73.                  ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
    
  74.                  name="article_archive"),
    
  75.         ]
    
  76. 
    
  77.     **Example myapp/article_archive.html**:
    
  78. 
    
  79.     .. code-block:: html+django
    
  80. 
    
  81.         <ul>
    
  82.             {% for article in latest %}
    
  83.                 <li>{{ article.pub_date }}: {{ article.title }}</li>
    
  84.             {% endfor %}
    
  85.         </ul>
    
  86. 
    
  87.     This will output all articles.
    
  88. 
    
  89. ``YearArchiveView``
    
  90. ===================
    
  91. 
    
  92. .. class:: YearArchiveView
    
  93. 
    
  94.     A yearly archive page showing all available months in a given year. Objects
    
  95.     with a date in the *future* are not displayed unless you set
    
  96.     ``allow_future`` to ``True``.
    
  97. 
    
  98.     **Ancestors (MRO)**
    
  99. 
    
  100.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  101.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  102.     * :class:`django.views.generic.dates.BaseYearArchiveView`
    
  103.     * :class:`django.views.generic.dates.YearMixin`
    
  104.     * :class:`django.views.generic.dates.BaseDateListView`
    
  105.     * :class:`django.views.generic.list.MultipleObjectMixin`
    
  106.     * :class:`django.views.generic.dates.DateMixin`
    
  107.     * :class:`django.views.generic.base.View`
    
  108. 
    
  109.     .. attribute:: make_object_list
    
  110. 
    
  111.         A boolean specifying whether to retrieve the full list of objects for
    
  112.         this year and pass those to the template. If ``True``, the list of
    
  113.         objects will be made available to the context. If ``False``, the
    
  114.         ``None`` queryset will be used as the object list. By default, this is
    
  115.         ``False``.
    
  116. 
    
  117.     .. method:: get_make_object_list()
    
  118. 
    
  119.         Determine if an object list will be returned as part of the context.
    
  120.         Returns :attr:`~YearArchiveView.make_object_list` by default.
    
  121. 
    
  122.     **Context**
    
  123. 
    
  124.     In addition to the context provided by
    
  125.     :class:`django.views.generic.list.MultipleObjectMixin` (via
    
  126.     :class:`django.views.generic.dates.BaseDateListView`), the template's
    
  127.     context will be:
    
  128. 
    
  129.     * ``date_list``: A :meth:`QuerySet <django.db.models.query.QuerySet.dates>`
    
  130.       object containing all months that have objects available according to
    
  131.       ``queryset``, represented as :class:`datetime.datetime` objects, in
    
  132.       ascending order.
    
  133. 
    
  134.     * ``year``: A :class:`~datetime.date` object
    
  135.       representing the given year.
    
  136. 
    
  137.     * ``next_year``: A :class:`~datetime.date` object
    
  138.       representing the first day of the next year, according to
    
  139.       :attr:`~BaseDateListView.allow_empty` and
    
  140.       :attr:`~DateMixin.allow_future`.
    
  141. 
    
  142.     * ``previous_year``: A :class:`~datetime.date` object
    
  143.       representing the first day of the previous year, according to
    
  144.       :attr:`~BaseDateListView.allow_empty` and
    
  145.       :attr:`~DateMixin.allow_future`.
    
  146. 
    
  147.     **Notes**
    
  148. 
    
  149.     * Uses a default ``template_name_suffix`` of ``_archive_year``.
    
  150. 
    
  151.     **Example myapp/views.py**::
    
  152. 
    
  153.         from django.views.generic.dates import YearArchiveView
    
  154. 
    
  155.         from myapp.models import Article
    
  156. 
    
  157.         class ArticleYearArchiveView(YearArchiveView):
    
  158.             queryset = Article.objects.all()
    
  159.             date_field = "pub_date"
    
  160.             make_object_list = True
    
  161.             allow_future = True
    
  162. 
    
  163.     **Example myapp/urls.py**::
    
  164. 
    
  165.         from django.urls import path
    
  166. 
    
  167.         from myapp.views import ArticleYearArchiveView
    
  168. 
    
  169.         urlpatterns = [
    
  170.             path('<int:year>/',
    
  171.                  ArticleYearArchiveView.as_view(),
    
  172.                  name="article_year_archive"),
    
  173.         ]
    
  174. 
    
  175.     **Example myapp/article_archive_year.html**:
    
  176. 
    
  177.     .. code-block:: html+django
    
  178. 
    
  179.         <ul>
    
  180.             {% for date in date_list %}
    
  181.                 <li>{{ date|date }}</li>
    
  182.             {% endfor %}
    
  183.         </ul>
    
  184. 
    
  185.         <div>
    
  186.             <h1>All Articles for {{ year|date:"Y" }}</h1>
    
  187.             {% for obj in object_list %}
    
  188.                 <p>
    
  189.                     {{ obj.title }} - {{ obj.pub_date|date:"F j, Y" }}
    
  190.                 </p>
    
  191.             {% endfor %}
    
  192.         </div>
    
  193. 
    
  194. ``MonthArchiveView``
    
  195. ====================
    
  196. 
    
  197. .. class:: MonthArchiveView
    
  198. 
    
  199.     A monthly archive page showing all objects in a given month. Objects with a
    
  200.     date in the *future* are not displayed unless you set ``allow_future`` to
    
  201.     ``True``.
    
  202. 
    
  203.     **Ancestors (MRO)**
    
  204. 
    
  205.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  206.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  207.     * :class:`django.views.generic.dates.BaseMonthArchiveView`
    
  208.     * :class:`django.views.generic.dates.YearMixin`
    
  209.     * :class:`django.views.generic.dates.MonthMixin`
    
  210.     * :class:`django.views.generic.dates.BaseDateListView`
    
  211.     * :class:`django.views.generic.list.MultipleObjectMixin`
    
  212.     * :class:`django.views.generic.dates.DateMixin`
    
  213.     * :class:`django.views.generic.base.View`
    
  214. 
    
  215.     **Context**
    
  216. 
    
  217.     In addition to the context provided by
    
  218.     :class:`~django.views.generic.list.MultipleObjectMixin` (via
    
  219.     :class:`~django.views.generic.dates.BaseDateListView`), the template's
    
  220.     context will be:
    
  221. 
    
  222.     * ``date_list``: A :meth:`QuerySet <django.db.models.query.QuerySet.dates>`
    
  223.       object containing all days that have objects available in the given month,
    
  224.       according to ``queryset``, represented as :class:`datetime.datetime`
    
  225.       objects, in ascending order.
    
  226. 
    
  227.     * ``month``: A :class:`~datetime.date` object
    
  228.       representing the given month.
    
  229. 
    
  230.     * ``next_month``: A :class:`~datetime.date` object
    
  231.       representing the first day of the next month, according to
    
  232.       :attr:`~BaseDateListView.allow_empty` and
    
  233.       :attr:`~DateMixin.allow_future`.
    
  234. 
    
  235.     * ``previous_month``: A :class:`~datetime.date` object
    
  236.       representing the first day of the previous month, according to
    
  237.       :attr:`~BaseDateListView.allow_empty` and
    
  238.       :attr:`~DateMixin.allow_future`.
    
  239. 
    
  240.     **Notes**
    
  241. 
    
  242.     * Uses a default ``template_name_suffix`` of ``_archive_month``.
    
  243. 
    
  244.     **Example myapp/views.py**::
    
  245. 
    
  246.         from django.views.generic.dates import MonthArchiveView
    
  247. 
    
  248.         from myapp.models import Article
    
  249. 
    
  250.         class ArticleMonthArchiveView(MonthArchiveView):
    
  251.             queryset = Article.objects.all()
    
  252.             date_field = "pub_date"
    
  253.             allow_future = True
    
  254. 
    
  255.     **Example myapp/urls.py**::
    
  256. 
    
  257.         from django.urls import path
    
  258. 
    
  259.         from myapp.views import ArticleMonthArchiveView
    
  260. 
    
  261.         urlpatterns = [
    
  262.             # Example: /2012/08/
    
  263.             path('<int:year>/<int:month>/',
    
  264.                  ArticleMonthArchiveView.as_view(month_format='%m'),
    
  265.                  name="archive_month_numeric"),
    
  266.             # Example: /2012/aug/
    
  267.             path('<int:year>/<str:month>/',
    
  268.                  ArticleMonthArchiveView.as_view(),
    
  269.                  name="archive_month"),
    
  270.         ]
    
  271. 
    
  272.     **Example myapp/article_archive_month.html**:
    
  273. 
    
  274.     .. code-block:: html+django
    
  275. 
    
  276.         <ul>
    
  277.             {% for article in object_list %}
    
  278.                 <li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li>
    
  279.             {% endfor %}
    
  280.         </ul>
    
  281. 
    
  282.         <p>
    
  283.             {% if previous_month %}
    
  284.                 Previous Month: {{ previous_month|date:"F Y" }}
    
  285.             {% endif %}
    
  286.             {% if next_month %}
    
  287.                 Next Month: {{ next_month|date:"F Y" }}
    
  288.             {% endif %}
    
  289.         </p>
    
  290. 
    
  291. ``WeekArchiveView``
    
  292. ===================
    
  293. 
    
  294. .. class:: WeekArchiveView
    
  295. 
    
  296.     A weekly archive page showing all objects in a given week. Objects with a
    
  297.     date in the *future* are not displayed unless you set ``allow_future`` to
    
  298.     ``True``.
    
  299. 
    
  300.     **Ancestors (MRO)**
    
  301. 
    
  302.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  303.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  304.     * :class:`django.views.generic.dates.BaseWeekArchiveView`
    
  305.     * :class:`django.views.generic.dates.YearMixin`
    
  306.     * :class:`django.views.generic.dates.WeekMixin`
    
  307.     * :class:`django.views.generic.dates.BaseDateListView`
    
  308.     * :class:`django.views.generic.list.MultipleObjectMixin`
    
  309.     * :class:`django.views.generic.dates.DateMixin`
    
  310.     * :class:`django.views.generic.base.View`
    
  311. 
    
  312.     **Context**
    
  313. 
    
  314.     In addition to the context provided by
    
  315.     :class:`~django.views.generic.list.MultipleObjectMixin` (via
    
  316.     :class:`~django.views.generic.dates.BaseDateListView`), the template's
    
  317.     context will be:
    
  318. 
    
  319.     * ``week``: A :class:`~datetime.date` object
    
  320.       representing the first day of the given week.
    
  321. 
    
  322.     * ``next_week``: A :class:`~datetime.date` object
    
  323.       representing the first day of the next week, according to
    
  324.       :attr:`~BaseDateListView.allow_empty` and
    
  325.       :attr:`~DateMixin.allow_future`.
    
  326. 
    
  327.     * ``previous_week``: A :class:`~datetime.date` object
    
  328.       representing the first day of the previous week, according to
    
  329.       :attr:`~BaseDateListView.allow_empty` and
    
  330.       :attr:`~DateMixin.allow_future`.
    
  331. 
    
  332.     **Notes**
    
  333. 
    
  334.     * Uses a default ``template_name_suffix`` of ``_archive_week``.
    
  335. 
    
  336.     * The ``week_format`` attribute is a :func:`~time.strptime` format string
    
  337.       used to parse the week number. The following values are supported:
    
  338. 
    
  339.       * ``'%U'``: Based on the United States week system where the week
    
  340.         begins on Sunday. This is the default value.
    
  341. 
    
  342.       * ``'%W'``: Similar to ``'%U'``, except it assumes that the week
    
  343.         begins on Monday. This is not the same as the ISO 8601 week number.
    
  344. 
    
  345.       * ``'%V'``: ISO 8601 week number where the week begins on Monday.
    
  346. 
    
  347.     **Example myapp/views.py**::
    
  348. 
    
  349.         from django.views.generic.dates import WeekArchiveView
    
  350. 
    
  351.         from myapp.models import Article
    
  352. 
    
  353.         class ArticleWeekArchiveView(WeekArchiveView):
    
  354.             queryset = Article.objects.all()
    
  355.             date_field = "pub_date"
    
  356.             week_format = "%W"
    
  357.             allow_future = True
    
  358. 
    
  359.     **Example myapp/urls.py**::
    
  360. 
    
  361.         from django.urls import path
    
  362. 
    
  363.         from myapp.views import ArticleWeekArchiveView
    
  364. 
    
  365.         urlpatterns = [
    
  366.             # Example: /2012/week/23/
    
  367.             path('<int:year>/week/<int:week>/',
    
  368.                  ArticleWeekArchiveView.as_view(),
    
  369.                  name="archive_week"),
    
  370.         ]
    
  371. 
    
  372.     **Example myapp/article_archive_week.html**:
    
  373. 
    
  374.     .. code-block:: html+django
    
  375. 
    
  376.         <h1>Week {{ week|date:'W' }}</h1>
    
  377. 
    
  378.         <ul>
    
  379.             {% for article in object_list %}
    
  380.                 <li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li>
    
  381.             {% endfor %}
    
  382.         </ul>
    
  383. 
    
  384.         <p>
    
  385.             {% if previous_week %}
    
  386.                 Previous Week: {{ previous_week|date:"W" }} of year {{ previous_week|date:"Y" }}
    
  387.             {% endif %}
    
  388.             {% if previous_week and next_week %}--{% endif %}
    
  389.             {% if next_week %}
    
  390.                 Next week: {{ next_week|date:"W" }} of year {{ next_week|date:"Y" }}
    
  391.             {% endif %}
    
  392.         </p>
    
  393. 
    
  394.     In this example, you are outputting the week number. Keep in mind that week
    
  395.     numbers computed by the :tfilter:`date` template filter with the ``'W'``
    
  396.     format character are not always the same as those computed by
    
  397.     :func:`~time.strftime` and :func:`~time.strptime` with the ``'%W'`` format
    
  398.     string. For year 2015, for example, week numbers output by :tfilter:`date`
    
  399.     are higher by one compared to those output by :func:`~time.strftime`. There
    
  400.     isn't an equivalent for the ``'%U'`` :func:`~time.strftime` format string
    
  401.     in :tfilter:`date`. Therefore, you should avoid using :tfilter:`date` to
    
  402.     generate URLs for ``WeekArchiveView``.
    
  403. 
    
  404. ``DayArchiveView``
    
  405. ==================
    
  406. 
    
  407. .. class:: DayArchiveView
    
  408. 
    
  409.     A day archive page showing all objects in a given day. Days in the future
    
  410.     throw a 404 error, regardless of whether any objects exist for future days,
    
  411.     unless you set ``allow_future`` to ``True``.
    
  412. 
    
  413.     **Ancestors (MRO)**
    
  414. 
    
  415.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  416.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  417.     * :class:`django.views.generic.dates.BaseDayArchiveView`
    
  418.     * :class:`django.views.generic.dates.YearMixin`
    
  419.     * :class:`django.views.generic.dates.MonthMixin`
    
  420.     * :class:`django.views.generic.dates.DayMixin`
    
  421.     * :class:`django.views.generic.dates.BaseDateListView`
    
  422.     * :class:`django.views.generic.list.MultipleObjectMixin`
    
  423.     * :class:`django.views.generic.dates.DateMixin`
    
  424.     * :class:`django.views.generic.base.View`
    
  425. 
    
  426.     **Context**
    
  427. 
    
  428.     In addition to the context provided by
    
  429.     :class:`~django.views.generic.list.MultipleObjectMixin` (via
    
  430.     :class:`~django.views.generic.dates.BaseDateListView`), the template's
    
  431.     context will be:
    
  432. 
    
  433.     * ``day``: A :class:`~datetime.date` object
    
  434.       representing the given day.
    
  435. 
    
  436.     * ``next_day``: A :class:`~datetime.date` object
    
  437.       representing the next day, according to
    
  438.       :attr:`~BaseDateListView.allow_empty` and
    
  439.       :attr:`~DateMixin.allow_future`.
    
  440. 
    
  441.     * ``previous_day``: A :class:`~datetime.date` object
    
  442.       representing the previous day, according to
    
  443.       :attr:`~BaseDateListView.allow_empty` and
    
  444.       :attr:`~DateMixin.allow_future`.
    
  445. 
    
  446.     * ``next_month``: A :class:`~datetime.date` object
    
  447.       representing the first day of the next month, according to
    
  448.       :attr:`~BaseDateListView.allow_empty` and
    
  449.       :attr:`~DateMixin.allow_future`.
    
  450. 
    
  451.     * ``previous_month``: A :class:`~datetime.date` object
    
  452.       representing the first day of the previous month, according to
    
  453.       :attr:`~BaseDateListView.allow_empty` and
    
  454.       :attr:`~DateMixin.allow_future`.
    
  455. 
    
  456.     **Notes**
    
  457. 
    
  458.     * Uses a default ``template_name_suffix`` of ``_archive_day``.
    
  459. 
    
  460.     **Example myapp/views.py**::
    
  461. 
    
  462.         from django.views.generic.dates import DayArchiveView
    
  463. 
    
  464.         from myapp.models import Article
    
  465. 
    
  466.         class ArticleDayArchiveView(DayArchiveView):
    
  467.             queryset = Article.objects.all()
    
  468.             date_field = "pub_date"
    
  469.             allow_future = True
    
  470. 
    
  471.     **Example myapp/urls.py**::
    
  472. 
    
  473.         from django.urls import path
    
  474. 
    
  475.         from myapp.views import ArticleDayArchiveView
    
  476. 
    
  477.         urlpatterns = [
    
  478.             # Example: /2012/nov/10/
    
  479.             path('<int:year>/<str:month>/<int:day>/',
    
  480.                  ArticleDayArchiveView.as_view(),
    
  481.                  name="archive_day"),
    
  482.         ]
    
  483. 
    
  484.     **Example myapp/article_archive_day.html**:
    
  485. 
    
  486.     .. code-block:: html+django
    
  487. 
    
  488.         <h1>{{ day }}</h1>
    
  489. 
    
  490.         <ul>
    
  491.             {% for article in object_list %}
    
  492.                 <li>{{ article.pub_date|date:"F j, Y" }}: {{ article.title }}</li>
    
  493.             {% endfor %}
    
  494.         </ul>
    
  495. 
    
  496.         <p>
    
  497.             {% if previous_day %}
    
  498.                 Previous Day: {{ previous_day }}
    
  499.             {% endif %}
    
  500.             {% if previous_day and next_day %}--{% endif %}
    
  501.             {% if next_day %}
    
  502.                 Next Day: {{ next_day }}
    
  503.             {% endif %}
    
  504.         </p>
    
  505. 
    
  506. ``TodayArchiveView``
    
  507. ====================
    
  508. 
    
  509. .. class:: TodayArchiveView
    
  510. 
    
  511.     A day archive page showing all objects for *today*. This is exactly the
    
  512.     same as :class:`django.views.generic.dates.DayArchiveView`, except today's
    
  513.     date is used instead of the ``year``/``month``/``day`` arguments.
    
  514. 
    
  515.     **Ancestors (MRO)**
    
  516. 
    
  517.     * :class:`django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  518.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  519.     * :class:`django.views.generic.dates.BaseTodayArchiveView`
    
  520.     * :class:`django.views.generic.dates.BaseDayArchiveView`
    
  521.     * :class:`django.views.generic.dates.YearMixin`
    
  522.     * :class:`django.views.generic.dates.MonthMixin`
    
  523.     * :class:`django.views.generic.dates.DayMixin`
    
  524.     * :class:`django.views.generic.dates.BaseDateListView`
    
  525.     * :class:`django.views.generic.list.MultipleObjectMixin`
    
  526.     * :class:`django.views.generic.dates.DateMixin`
    
  527.     * :class:`django.views.generic.base.View`
    
  528. 
    
  529.     **Notes**
    
  530. 
    
  531.     * Uses a default ``template_name_suffix`` of ``_archive_today``.
    
  532. 
    
  533.     **Example myapp/views.py**::
    
  534. 
    
  535.         from django.views.generic.dates import TodayArchiveView
    
  536. 
    
  537.         from myapp.models import Article
    
  538. 
    
  539.         class ArticleTodayArchiveView(TodayArchiveView):
    
  540.             queryset = Article.objects.all()
    
  541.             date_field = "pub_date"
    
  542.             allow_future = True
    
  543. 
    
  544.     **Example myapp/urls.py**::
    
  545. 
    
  546.         from django.urls import path
    
  547. 
    
  548.         from myapp.views import ArticleTodayArchiveView
    
  549. 
    
  550.         urlpatterns = [
    
  551.             path('today/',
    
  552.                  ArticleTodayArchiveView.as_view(),
    
  553.                  name="archive_today"),
    
  554.         ]
    
  555. 
    
  556.     .. admonition:: Where is the example template for ``TodayArchiveView``?
    
  557. 
    
  558.         This view uses by default the same template as the
    
  559.         :class:`~DayArchiveView`, which is in the previous example. If you need
    
  560.         a different template, set the ``template_name`` attribute to be the
    
  561.         name of the new template.
    
  562. 
    
  563. ``DateDetailView``
    
  564. ==================
    
  565. 
    
  566. .. class:: DateDetailView
    
  567. 
    
  568.     A page representing an individual object. If the object has a date value in
    
  569.     the future, the view will throw a 404 error by default, unless you set
    
  570.     ``allow_future`` to ``True``.
    
  571. 
    
  572.     **Ancestors (MRO)**
    
  573. 
    
  574.     * :class:`django.views.generic.detail.SingleObjectTemplateResponseMixin`
    
  575.     * :class:`django.views.generic.base.TemplateResponseMixin`
    
  576.     * :class:`django.views.generic.dates.BaseDateDetailView`
    
  577.     * :class:`django.views.generic.dates.YearMixin`
    
  578.     * :class:`django.views.generic.dates.MonthMixin`
    
  579.     * :class:`django.views.generic.dates.DayMixin`
    
  580.     * :class:`django.views.generic.dates.DateMixin`
    
  581.     * :class:`django.views.generic.detail.BaseDetailView`
    
  582.     * :class:`django.views.generic.detail.SingleObjectMixin`
    
  583.     * :class:`django.views.generic.base.View`
    
  584. 
    
  585.     **Context**
    
  586. 
    
  587.     * Includes the single object associated with the ``model`` specified in
    
  588.       the ``DateDetailView``.
    
  589. 
    
  590.     **Notes**
    
  591. 
    
  592.     * Uses a default ``template_name_suffix`` of ``_detail``.
    
  593. 
    
  594.     **Example myapp/urls.py**::
    
  595. 
    
  596.         from django.urls import path
    
  597.         from django.views.generic.dates import DateDetailView
    
  598. 
    
  599.         urlpatterns = [
    
  600.             path('<int:year>/<str:month>/<int:day>/<int:pk>/',
    
  601.                  DateDetailView.as_view(model=Article, date_field="pub_date"),
    
  602.                  name="archive_date_detail"),
    
  603.         ]
    
  604. 
    
  605.     **Example myapp/article_detail.html**:
    
  606. 
    
  607.     .. code-block:: html+django
    
  608. 
    
  609.         <h1>{{ object.title }}</h1>
    
  610. 
    
  611. .. note::
    
  612. 
    
  613.     All of the generic views listed above have matching ``Base`` views that
    
  614.     only differ in that they do not include the
    
  615.     :class:`~django.views.generic.list.MultipleObjectTemplateResponseMixin`
    
  616.     (for the archive views) or
    
  617.     :class:`~django.views.generic.detail.SingleObjectTemplateResponseMixin`
    
  618.     (for the :class:`DateDetailView`):
    
  619. 
    
  620.     .. class:: BaseArchiveIndexView
    
  621. 
    
  622.     .. class:: BaseYearArchiveView
    
  623. 
    
  624.     .. class:: BaseMonthArchiveView
    
  625. 
    
  626.     .. class:: BaseWeekArchiveView
    
  627. 
    
  628.     .. class:: BaseDayArchiveView
    
  629. 
    
  630.     .. class:: BaseTodayArchiveView
    
  631. 
    
  632.     .. class:: BaseDateDetailView