mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #26348 -- Added TruncTime and exposed it through the __time lookup.
Thanks Tim for the review.
This commit is contained in:
parent
082c52dbed
commit
8a4f017f45
12 changed files with 119 additions and 3 deletions
|
@ -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'
|
||||
|
|
|
@ -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``
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue