mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
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).
This commit is contained in:
parent
6700c90935
commit
2dc93bb10a
8 changed files with 117 additions and 14 deletions
|
@ -11,6 +11,14 @@ from django.utils import six
|
|||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
class Alarm(models.Model):
|
||||
desc = models.CharField(max_length=100)
|
||||
time = models.TimeField()
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.time, self.desc)
|
||||
|
||||
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
|
|
36
tests/lookup/test_timefield.py
Normal file
36
tests/lookup/test_timefield.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Alarm
|
||||
|
||||
|
||||
class TimeFieldLookupTests(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
# Create a few Alarms
|
||||
self.al1 = Alarm.objects.create(desc='Early', time='05:30')
|
||||
self.al2 = Alarm.objects.create(desc='Late', time='10:00')
|
||||
self.al3 = Alarm.objects.create(desc='Precise', time='12:34:56')
|
||||
|
||||
def test_hour_lookups(self):
|
||||
self.assertQuerysetEqual(
|
||||
Alarm.objects.filter(time__hour=5),
|
||||
['<Alarm: 05:30:00 (Early)>'],
|
||||
ordered=False
|
||||
)
|
||||
|
||||
def test_minute_lookups(self):
|
||||
self.assertQuerysetEqual(
|
||||
Alarm.objects.filter(time__minute=30),
|
||||
['<Alarm: 05:30:00 (Early)>'],
|
||||
ordered=False
|
||||
)
|
||||
|
||||
def test_second_lookups(self):
|
||||
self.assertQuerysetEqual(
|
||||
Alarm.objects.filter(time__second=56),
|
||||
['<Alarm: 12:34:56 (Precise)>'],
|
||||
ordered=False
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue