Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use date_extract_sql() for DateFields

Refs #21821
  • Loading branch information...
commit 1c360dbbf56b76e1df7c945458ae2987306fcfcd 1 parent b86321e
@akaariai akaariai authored
Showing with 7 additions and 4 deletions.
  1. +7 −4 django/db/models/lookups.py
View
11 django/db/models/lookups.py
@@ -281,12 +281,15 @@ class Range(Between):
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
Please sign in to comment.
Something went wrong with that request. Please try again.