Opened 3 years ago

Closed 16 months ago

#22316 closed New feature (fixed)

TimeField lacks hour/minute filters

Reported by: Matthew Somerville Owned by: Matthew Somerville
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#8424 added hour/minute/second filter lookups to DateTimeField, but not TimeField. I'm not sure if this was deliberate, but it would seem useful to have the functionality on TimeFields too if possible.

A workaround is to use a DateTimeField and hide/set the date part within the model.

Change History (12)

comment:1 Changed 3 years ago by Simon Charette

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted
Version: 1.6master

From the discussion on #8424 it looks like those lookups were only added to DateTimeField to prevent possible clashes due to ORM limitations.

Now that the ORM lookup system has been overhauled (see #16187) it looks like django.db.lookups.DateLookup could be refactored to also account for TimeField.

comment:2 Changed 3 years ago by Marc Tamlyn

Owner: changed from nobody to Marc Tamlyn
Status: newassigned

comment:3 Changed 3 years ago by Aymeric Augustin

I added the lookups to DateTimeField despite the potential for clashes. I was working in the context of time zone support and simply didn't think about TimeField.

comment:4 Changed 3 years ago by omer.drow@…

Will this be implemented in 1.7?

comment:5 Changed 3 years ago by Aymeric Augustin

No, 1.7 is feature frozen.

comment:6 Changed 16 months ago by Tim Graham

Summary: TimeFIeld lacks hour/minute filtersTimeField lacks hour/minute filters

comment:7 Changed 16 months ago by Matthew Somerville

It looks like this was actually implemented for non-SQLite backends in 1.7 (I think as a side effect of #16187?), but on master it doesn't work in SQLite due to it having to use Python for date/time related functions. I have opened a PR that hopefully adds SQLite support for https://github.com/django/django/pull/4698

comment:8 Changed 16 months ago by Tim Graham

Has patch: set
Patch needs improvement: set

comment:9 Changed 16 months ago by Matthew Somerville

Owner: changed from Marc Tamlyn to Matthew Somerville

Will work on at DjangoCon EU sprint :)

comment:10 Changed 16 months ago by Matthew Somerville

Patch needs improvement: unset

comment:11 Changed 16 months ago by Marc Tamlyn

Triage Stage: AcceptedReady for checkin

comment:12 Changed 16 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 2dc93bb:

Fixed #22316 -- Added time filters to TimeField on SQLite.

This was implemented for non-SQLite backends in 1.7 (as a
side effect of #16187).

Note: See TracTickets for help on using tickets.
Back to Top