Ticket #8424: time_filters.diff
File time_filters.diff, 4.5 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/where.py
162 162 params) 163 163 elif lookup_type in ('range', 'year'): 164 164 return ('%s BETWEEN %%s and %%s' % field_sql, params) 165 elif lookup_type in ('month', 'day' ):165 elif lookup_type in ('month', 'day', 'hour', 'minute', 'second'): 166 166 return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, 167 167 field_sql), params) 168 168 elif lookup_type == 'isnull': -
django/db/models/sql/constants.py
4 4 QUERY_TERMS = dict([(x, None) for x in ( 5 5 'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in', 6 6 'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year', 7 'month', 'day', 'isnull', 'search', 'regex', 'iregex', 7 'month', 'day', 'hour', 'minute', 'second', 'isnull', 'search', 'regex', 8 'iregex', 8 9 )]) 9 10 10 11 # Size of each "chunk" for get_iterator calls. -
django/db/models/fields/__init__.py
208 208 if hasattr(value, 'as_sql'): 209 209 sql, params = value.as_sql() 210 210 return QueryWrapper(('(%s)' % sql), params) 211 if lookup_type in ('regex', 'iregex', 'month', 'day', 'search'): 211 if lookup_type in ('regex', 'iregex', 'month', 'day', 'hour', 212 'minute', 'second', 'search'): 212 213 return [value] 213 214 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'): 214 215 return [self.get_db_prep_value(value)] -
tests/modeltests/basic/models.py
75 75 >>> Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28) 76 76 <Article: Area woman programs in Python> 77 77 78 78 79 # The "__exact" lookup type can be omitted, as a shortcut. 79 80 >>> Article.objects.get(id=1) 80 81 <Article: Area woman programs in Python> … … 88 89 >>> Article.objects.filter(pub_date__year=2005, pub_date__month=7) 89 90 [<Article: Area woman programs in Python>] 90 91 92 >>> Article.objects.filter(pub_date__hour=0) 93 [<Article: Area woman programs in Python>] 94 >>> Article.objects.filter(pub_date__hour=1) 95 [] 96 97 >>> Article.objects.filter(pub_date__minute=0) 98 [<Article: Area woman programs in Python>] 99 >>> Article.objects.filter(pub_date__minute=1) 100 [] 101 102 >>> Article.objects.filter(pub_date__second=0) 103 [<Article: Area woman programs in Python>] 104 >>> Article.objects.filter(pub_date__second=1) 105 [] 106 91 107 # Django raises an Article.DoesNotExist exception for get() if the parameters 92 108 # don't match any object. 93 109 >>> Article.objects.get(id__exact=2) -
docs/db-api.txt
1580 1580 Note this will match any record with a pub_date on the third day of the month, 1581 1581 such as January 3, July 3, etc. 1582 1582 1583 hour 1584 ~~~~ 1585 1586 For date/datetime fields, exact hour match. 1587 1588 Example:: 1589 1590 Entry.objects.filter(pub_date__hour=3) 1591 1592 SQL equivalent:: 1593 1594 SELECT ... WHERE EXTRACT('hour' FROM pub_date) = '3'; 1595 1596 (The exact SQL syntax varies for each database engine.) 1597 1598 This will match every record with a pub_date that occurred between 1599 3:00 AM and 3:59 AM. 1600 1601 minute 1602 ~~~~ 1603 1604 For date/datetime fields, exact minute match. 1605 1606 Example:: 1607 1608 Entry.objects.filter(pub_date__minute=30) 1609 1610 SQL equivalent:: 1611 1612 SELECT ... WHERE EXTRACT('minute' FROM pub_date) = '30'; 1613 1614 (The exact SQL syntax varies for each database engine.) 1615 1616 This will match every record with a pub_date that occurred at the 30th 1617 minute of any hour, such as 8:30 AM or 11:30 PM. 1618 1619 second 1620 ~~~~ 1621 1622 For date/datetime fields, exact second match. 1623 1624 Example:: 1625 1626 Entry.objects.filter(pub_date__second=0) 1627 1628 SQL equivalent:: 1629 1630 SELECT ... WHERE EXTRACT('second' FROM pub_date) = '0'; 1631 1632 (The exact SQL syntax varies for each database engine.) 1633 1634 This will match every record with a pub_date that occurred at the 0th 1635 second of any minute. 1636 1583 1637 isnull 1584 1638 ~~~~~~ 1585 1639