1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Use date_extract_sql() for DateFields

Refs #21821
This commit is contained in:
Anssi Kääriäinen 2014-01-20 05:02:29 +02:00
parent b86321e9a4
commit 1c360dbbf5

View File

@ -281,12 +281,15 @@ default_lookups['range'] = Range
class DateLookup(BuiltinLookup):
def process_lhs(self, qn, connection, lhs=None):
from django.db.models import DateTimeField
lhs, params = super(DateLookup, self).process_lhs(qn, connection, lhs)
tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None
sql, tz_params = connection.ops.datetime_extract_sql(self.extract_type, lhs, tzname)
return connection.ops.lookup_cast(self.lookup_name) % sql, tz_params
if isinstance(self.lhs.output_type, DateTimeField):
tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None
sql, tz_params = connection.ops.datetime_extract_sql(self.extract_type, lhs, tzname)
return connection.ops.lookup_cast(self.lookup_name) % sql, tz_params
else:
return connection.ops.date_extract_sql(self.lookup_name, lhs), []
def get_rhs_op(self, connection, rhs):
return '= %s' % rhs