Ticket #9596: dj_date_lookup_c.2.patch

File dj_date_lookup_c.2.patch, 2.6 KB (added by Scott <django@…>, 13 years ago)

patch c_2

  • django/db/models/sql/where.py

     
    160160                return ('%s IN %s' % (field_sql, extra), params)
    161161            return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(params))),
    162162                    params)
    163         elif lookup_type in ('range', 'year'):
     163        elif lookup_type in ('range', 'year', 'date'):
    164164            return ('%s BETWEEN %%s and %%s' % field_sql, params)
    165165        elif lookup_type in ('month', 'day'):
    166166            return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type,
  • django/db/models/sql/constants.py

     
    44QUERY_TERMS = dict([(x, None) for x in (
    55    'exact', 'iexact', 'contains', 'icontains', 'gt', 'gte', 'lt', 'lte', 'in',
    66    'startswith', 'istartswith', 'endswith', 'iendswith', 'range', 'year',
    7     'month', 'day', 'isnull', 'search', 'regex', 'iregex',
     7    'month', 'day', 'isnull', 'search', 'regex', 'iregex', 'date',
    88    )])
    99
    1010# Size of each "chunk" for get_iterator calls.
  • django/db/models/fields/__init__.py

     
    212212            return ["%%%s" % connection.ops.prep_for_like_query(value)]
    213213        elif lookup_type == 'isnull':
    214214            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)))
    215218        elif lookup_type == 'year':
    216219            try:
    217220                value = int(value)
  • docs/ref/models/querysets.txt

     
    11561156You can use ``range`` anywhere you can use ``BETWEEN`` in SQL -- for dates,
    11571157numbers and even characters.
    11581158
     1159date
     1160~~~~
     1161
     1162Tests datetime fields for date equality, disregarding time.
     1163
     1164Example::
     1165
     1166    yesterday = datetime.date.today() - datetime.timedelta(1)
     1167    Entry.objects.filter(pub_datetime__date = yesterday)
     1168
     1169SQL equivalent::
     1170
     1171    SELECT ... WHERE pub_datetime BETWEEN '2008-11-12 00:00:00' and '2008-11-12 23:59:59';
     1172
    11591173year
    11601174~~~~
    11611175
Back to Top