diff options
| author | Sigurd Ljødal <sigurd@ljodal.no> | 2017-09-28 22:39:03 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-27 09:59:13 -0500 |
| commit | a455e732a0011dfbd15eddaa4fe60cb9439326e0 (patch) | |
| tree | 1df72fb36c377ae630e1bbc8a588662f8f3cb46f /docs | |
| parent | f229049d6cd186025f4033dc47608b0c9731e882 (diff) | |
Fixed #28650 -- Added TruncWeek database function.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 10 | ||||
| -rw-r--r-- | docs/ref/models/querysets.txt | 24 | ||||
| -rw-r--r-- | docs/releases/2.1.txt | 4 |
3 files changed, 32 insertions, 6 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 97634d3584..68943e8c8e 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -439,6 +439,7 @@ return: * "year": 2015-01-01 00:00:00+00:00 * "quarter": 2015-04-01 00:00:00+00:00 * "month": 2015-06-01 00:00:00+00:00 +* "week": 2015-06-15 00:00:00+00:00 * "day": 2015-06-15 00:00:00+00:00 * "hour": 2015-06-15 14:00:00+00:00 * "minute": 2015-06-15 14:30:00+00:00 @@ -452,6 +453,7 @@ values returned when this timezone is active will be: * "year": 2015-01-01 00:00:00+11:00 * "quarter": 2015-04-01 00:00:00+10:00 * "month": 2015-06-01 00:00:00+10:00 +* "week": 2015-06-16 00:00:00+10:00 * "day": 2015-06-16 00:00:00+10:00 * "hour": 2015-06-16 00:00:00+10:00 * "minute": 2015-06-16 00:30:00+10:00 @@ -504,6 +506,14 @@ Usage example:: .. attribute:: kind = 'month' +.. class:: TruncWeek(expression, output_field=None, tzinfo=None, **extra) + + .. versionadded:: 2.1 + + Truncates to midnight on the Monday of the week. + + .. attribute:: kind = 'week' + .. class:: TruncQuarter(expression, output_field=None, tzinfo=None, **extra) .. versionadded:: 2.0 diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 5064a42c9e..10251efc72 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -694,13 +694,15 @@ objects representing all available dates of a particular kind within the contents of the ``QuerySet``. ``field`` should be the name of a ``DateField`` of your model. -``kind`` should be either ``"year"``, ``"month"`` or ``"day"``. Each -``datetime.date`` object in the result list is "truncated" to the given -``type``. +``kind`` should be either ``"year"``, ``"month"``, ``"week"``, or ``"day"``. +Each :class:`datetime.date` object in the result list is "truncated" to the +given ``type``. * ``"year"`` returns a list of all distinct year values for the field. * ``"month"`` returns a list of all distinct year/month values for the field. +* ``"week"`` returns a list of all distinct year/week values for the field. All + dates will be a Monday. * ``"day"`` returns a list of all distinct year/month/day values for the field. @@ -713,6 +715,8 @@ Examples:: [datetime.date(2005, 1, 1)] >>> Entry.objects.dates('pub_date', 'month') [datetime.date(2005, 2, 1), datetime.date(2005, 3, 1)] + >>> Entry.objects.dates('pub_date', 'week') + [datetime.date(2005, 2, 14), datetime.date(2005, 3, 14)] >>> Entry.objects.dates('pub_date', 'day') [datetime.date(2005, 2, 20), datetime.date(2005, 3, 20)] >>> Entry.objects.dates('pub_date', 'day', order='DESC') @@ -720,6 +724,10 @@ Examples:: >>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 'day') [datetime.date(2005, 3, 20)] +.. versionchanged:: 2.1 + + "week" support was added. + ``datetimes()`` ~~~~~~~~~~~~~~~ @@ -731,9 +739,9 @@ contents of the ``QuerySet``. ``field_name`` should be the name of a ``DateTimeField`` of your model. -``kind`` should be either ``"year"``, ``"month"``, ``"day"``, ``"hour"``, -``"minute"`` or ``"second"``. Each ``datetime.datetime`` object in the result -list is "truncated" to the given ``type``. +``kind`` should be either ``"year"``, ``"month"``, ``"week"``, ``"day"``, +``"hour"``, ``"minute"``, or ``"second"``. Each :class:`datetime.datetime` +object in the result list is "truncated" to the given ``type``. ``order``, which defaults to ``'ASC'``, should be either ``'ASC'`` or ``'DESC'``. This specifies how to order the results. @@ -745,6 +753,10 @@ object. If it's ``None``, Django uses the :ref:`current time zone <default-current-time-zone>`. It has no effect when :setting:`USE_TZ` is ``False``. +.. versionchanged:: 2.1 + + "week" support was added. + .. _database-time-zone-definitions: .. note:: diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index 24ab0faa50..323da06fd6 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -173,6 +173,10 @@ Models * The new :class:`~django.db.models.functions.Replace` database function replaces strings in an expression. +* The new :class:`~django.db.models.functions.TruncWeek` function truncates + :class:`~django.db.models.DateField` and + :class:`~django.db.models.DateTimeField` to the Monday of a week. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ |
