diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-06-18 23:39:26 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-07-08 12:35:34 -0400 |
| commit | 8a4f017f4565c51c83aabb61a816e334e8638432 (patch) | |
| tree | fa6f6a4fcaf158dd161ef85fa85c3072390626e6 /docs/ref | |
| parent | 082c52dbedd76c312cebf3b23e04c449a94c20b6 (diff) | |
Fixed #26348 -- Added TruncTime and exposed it through the __time lookup.
Thanks Tim for the review.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 11 | ||||
| -rw-r--r-- | docs/ref/models/querysets.txt | 21 |
2 files changed, 32 insertions, 0 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 20ceadde91..74198ed749 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -686,6 +686,17 @@ that deal with time-parts can be used with ``TimeField``:: truncate function. It's also registered as a transform on ``DateTimeField`` as ``__date``. +.. class:: TruncTime(expression, **extra) + +.. versionadded:: 1.11 + + .. attribute:: lookup_name = 'time' + .. attribute:: output_field = TimeField() + +``TruncTime`` casts ``expression`` to a time rather than using the built-in SQL +truncate function. It's also registered as a transform on ``DateTimeField`` as +``__time``. + .. class:: TruncDay(expression, output_field=None, tzinfo=None, **extra) .. attribute:: kind = 'day' diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 6985da5ca6..36d791db0e 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -2674,6 +2674,27 @@ 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:: time + +``time`` +~~~~~~~~ + +.. versionadded:: 1.11 + +For datetime fields, casts the value as time. Allows chaining additional field +lookups. Takes a :class:`datetime.time` value. + +Example:: + + Entry.objects.filter(pub_date__time=datetime.time(14, 30)) + Entry.objects.filter(pub_date__time__between=(datetime.time(8), datetime.time(17))) + +(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:: hour ``hour`` |
