Opened 19 months ago

Closed 4 months ago

#22316 closed New feature (fixed)

TimeField lacks hour/minute filters

Reported by: dracos Owned by: dracos
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


#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 19 months ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.6 to master

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 19 months ago by mjtamlyn

  • Owner changed from nobody to mjtamlyn
  • Status changed from new to assigned

comment:3 Changed 19 months ago by aaugustin

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 19 months ago by omer.drow@…

Will this be implemented in 1.7?

comment:5 Changed 19 months ago by aaugustin

No, 1.7 is feature frozen.

comment:6 Changed 5 months ago by timgraham

  • Summary changed from TimeFIeld lacks hour/minute filters to TimeField lacks hour/minute filters

comment:7 Changed 5 months ago by dracos

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

comment:8 Changed 4 months ago by timgraham

  • Has patch set
  • Patch needs improvement set

comment:9 Changed 4 months ago by dracos

  • Owner changed from mjtamlyn to dracos

Will work on at DjangoCon EU sprint :)

comment:10 Changed 4 months ago by dracos

  • Patch needs improvement unset

comment:11 Changed 4 months ago by mjtamlyn

  • Triage Stage changed from Accepted to Ready for checkin

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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