diff options
| author | Mads Jensen <mje@inducks.org> | 2016-11-11 14:01:40 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-11-11 08:01:40 -0500 |
| commit | 1446902be48ebf19bfe484371897a2815dd21fca (patch) | |
| tree | 25945ce54301b3b33d4e975bfed5421ea5224d91 /docs/ref | |
| parent | 2dc07da497f5ae95ad34a4714e330fae1fa8413c (diff) | |
Fixed #25240 -- Added ExtractWeek and exposed it through the __week lookup.
Thanks to Mariusz Felisiak and Tim Graham for review.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 15 | ||||
| -rw-r--r-- | docs/ref/models/querysets.txt | 22 |
2 files changed, 37 insertions, 0 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 0d9c80fa25..ad653a710b 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -313,6 +313,7 @@ Given the datetime ``2015-06-15 23:30:01.000321+00:00``, the built-in * "year": 2015 * "month": 6 * "day": 15 +* "week": 25 * "week_day": 2 * "hour": 23 * "minute": 30 @@ -340,6 +341,14 @@ returned when this timezone is active will be the same as above except for: >>> (dt.isoweekday() % 7) + 1 2 +.. admonition:: ``week`` values + + The ``week`` ``lookup_type`` is calculated based on `ISO-8601 + <https://en.wikipedia.org/wiki/ISO-8601>`_, i.e., + a week starts on a Monday. The first week is the one with the majority + of the days, i.e., a week that starts on or before Thursday. The value + returned is in the range 1 to 52 or 53. + Each ``lookup_name`` above has a corresponding ``Extract`` subclass (listed below) that should typically be used instead of the more verbose equivalent, e.g. use ``ExtractYear(...)`` rather than ``Extract(..., lookup_name='year')``. @@ -382,6 +391,12 @@ Usage example:: .. attribute:: lookup_name = 'week_day' +.. class:: ExtractWeek(expression, tzinfo=None, **extra) + + .. versionadded:: 1.11 + + .. attribute:: lookup_name = 'week' + These are logically equivalent to ``Extract('date_field', lookup_name)``. Each class is also a ``Transform`` registered on ``DateField`` and ``DateTimeField`` as ``__(lookup_name)``, e.g. ``__year``. diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 7bcf2fc6ed..0d89f221b9 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -2703,6 +2703,28 @@ When :setting:`USE_TZ` is ``True``, datetime fields are converted to the current time zone before filtering. This requires :ref:`time zone definitions in the database <database-time-zone-definitions>`. +.. fieldlookup:: week + +``week`` +~~~~~~~~ + +.. versionadded:: 1.11 + +For date and datetime fields, return the week number (1-52 or 53) according +to `ISO-8601 <https://en.wikipedia.org/wiki/ISO-8601>`_, i.e., weeks start +on a Monday and the first week starts on or before Thursday. + +Example:: + + Entry.objects.filter(pub_date__week=52) + Entry.objects.filter(pub_date__week__gte=32, pub_date__week__lte=38) + +(No equivalent SQL code fragment is included for this lookup because +implementation of the relevant query varies among different database engines.) + +When :setting:`USE_TZ` is ``True``, fields are converted to the current time +zone before filtering. + .. fieldlookup:: week_day ``week_day`` |
