Ticket #9596: dj_date_lookup_c_3.patch
File dj_date_lookup_c_3.patch, 3.7 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/where.py
160 160 return ('%s IN %s' % (field_sql, extra), params) 161 161 return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(params))), 162 162 params) 163 elif lookup_type in ('range', 'year' ):163 elif lookup_type in ('range', 'year', 'date'): 164 164 return ('%s BETWEEN %%s and %%s' % field_sql, params) 165 165 elif lookup_type in ('month', 'day'): 166 166 return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, -
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', 'isnull', 'search', 'regex', 'iregex', 'date', 8 8 )]) 9 9 10 10 # Size of each "chunk" for get_iterator calls. -
django/db/models/fields/__init__.py
212 212 return ["%%%s" % connection.ops.prep_for_like_query(value)] 213 213 elif lookup_type == 'isnull': 214 214 return [] 215 elif lookup_type == 'date': 216 return self.get_db_prep_lookup('range', (datetime.datetime.combine(value, datetime.time.min), 217 datetime.datetime.combine(value, datetime.time.max))) 215 218 elif lookup_type == 'year': 216 219 try: 217 220 value = int(value) -
tests/modeltests/lookup/models.py
383 383 [<Article: barfoobaz>, <Article: baz>, <Article: bazbaRFOO>, <Article: foobarbaz>, <Article: foobaz>] 384 384 >>> Article.objects.filter(headline__iregex=r'b.*ar') 385 385 [<Article: bar>, <Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobar>, <Article: foobarbaz>] 386 387 # The __date lookup tests for datetime equality without the time 388 >>> for a in Article.objects.all(): 389 ... a.delete() 390 ... 391 >>> a17 = Article(pub_date=datetime(2008, 11, 14), headline="a17") 392 >>> a17.save() 393 >>> a18 = Article(pub_date=datetime(2008, 11, 14, 23, 59, 59), headline="a18") 394 >>> a18.save() 395 >>> a19 = Article(pub_date=datetime(2008, 11, 15), headline="a19") 396 >>> a19.save() 397 >>> for i in xrange(4): 398 ... print Article.objects.filter(pub_date__date=datetime(2008, 11, (13+i), i)) 399 ... 400 [] 401 [<Article: a18>, <Article: a17>] 402 [<Article: a19>] 403 [] 386 404 """} 387 405 388 406 -
docs/ref/models/querysets.txt
1156 1156 You can use ``range`` anywhere you can use ``BETWEEN`` in SQL -- for dates, 1157 1157 numbers and even characters. 1158 1158 1159 date 1160 ~~~~ 1161 1162 Tests datetime fields for date equality, disregarding time. 1163 1164 Example:: 1165 1166 yesterday = datetime.date.today() - datetime.timedelta(1) 1167 Entry.objects.filter(pub_datetime__date = yesterday) 1168 1169 SQL equivalent:: 1170 1171 SELECT ... WHERE pub_datetime BETWEEN '2008-11-12 00:00:00' and '2008-11-12 23:59:59'; 1172 1159 1173 year 1160 1174 ~~~~ 1161 1175