Ticket #9596: t9596-r9441-date_lookup.2.diff
File t9596-r9441-date_lookup.2.diff, 3.9 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/where.py
176 176 return ('%s IN %s' % (field_sql, extra), params) 177 177 return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(params))), 178 178 params) 179 elif lookup_type in ('range', 'year' ):179 elif lookup_type in ('range', 'year', 'date'): 180 180 return ('%s BETWEEN %%s and %%s' % field_sql, params) 181 181 elif lookup_type in ('month', 'day', 'week_day'): 182 182 return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, field_sql), -
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', 'week_day', ' isnull', 'search', 'regex', 'iregex',8 7 'month', 'day', 'week_day', 'date', 'isnull', 'search', 'regex', 'iregex', 8 )]) 9 9 10 10 # Size of each "chunk" for get_iterator calls. 11 11 # Larger values are slightly faster at the expense of more storage space. -
django/db/models/fields/__init__.py
220 220 return ["%%%s" % connection.ops.prep_for_like_query(value)] 221 221 elif lookup_type == 'isnull': 222 222 return [] 223 elif lookup_type == 'date': 224 return self.get_db_prep_lookup('range', (datetime.datetime.combine(value, datetime.time.min), 225 datetime.datetime.combine(value, datetime.time.max))) 223 226 elif lookup_type == 'year': 224 227 try: 225 228 value = int(value) -
tests/modeltests/lookup/models.py
390 390 [<Article: bar>, <Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobar>, <Article: foobarbaz>] 391 391 """ 392 392 393 394 393 if settings.DATABASE_ENGINE != 'mysql': 395 394 __test__['API_TESTS'] += r""" 396 395 # grouping and backreferences 397 396 >>> Article.objects.filter(headline__regex=r'b(.).*b\1') 398 397 [<Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobarbaz>] 399 398 """ 399 400 __test__['API_TESTS'] += r""" 401 # The __date lookup tests for datetime equality without the time 402 >>> for a in Article.objects.all(): 403 ... a.delete() 404 ... 405 >>> a17 = Article(pub_date=datetime(2008, 11, 14), headline="a17") 406 >>> a17.save() 407 >>> a18 = Article(pub_date=datetime(2008, 11, 14, 23, 59, 59), headline="a18") 408 >>> a18.save() 409 >>> a19 = Article(pub_date=datetime(2008, 11, 15), headline="a19") 410 >>> a19.save() 411 >>> for i in xrange(4): 412 ... print Article.objects.filter(pub_date__date=datetime(2008, 11, (13+i), i)) 413 ... 414 [] 415 [<Article: a18>, <Article: a17>] 416 [<Article: a19>] 417 [] 418 """ 419 -
docs/ref/models/querysets.txt
1295 1295 You can use ``range`` anywhere you can use ``BETWEEN`` in SQL -- for dates, 1296 1296 numbers and even characters. 1297 1297 1298 date 1299 ~~~~ 1300 1301 Tests datetime fields for date equality, disregarding time. 1302 1303 Example:: 1304 1305 yesterday = datetime.date.today() - datetime.timedelta(1) 1306 Entry.objects.filter(pub_datetime__date = yesterday) 1307 1308 SQL equivalent:: 1309 1310 SELECT ... WHERE pub_datetime BETWEEN '2008-11-12 00:00:00' AND '2008-11-12 23:59:59'; 1311 1298 1312 year 1299 1313 ~~~~ 1300 1314