summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2015-03-07 13:20:29 -0800
committerTim Graham <timograham@gmail.com>2015-06-02 08:49:10 -0400
commit44f3ee77166bd5c0e8a4604f2d96015268dce100 (patch)
tree733d47ee8d00d3934ae86d8b26275ad4fde4d371 /django/db/models
parent076a63e672370ff1735e7942cd1ae0990bcbd263 (diff)
Fixed #9596 -- Added date transform for DateTimeField.
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/fields/__init__.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 3351b4ad35..e6fa29a565 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1463,6 +1463,22 @@ class DateTimeField(DateField):
return super(DateTimeField, self).formfield(**defaults)
+@DateTimeField.register_lookup
+class DateTimeDateTransform(Transform):
+ lookup_name = 'date'
+
+ @cached_property
+ def output_field(self):
+ return DateField()
+
+ def as_sql(self, compiler, connection):
+ lhs, lhs_params = compiler.compile(self.lhs)
+ tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None
+ sql, tz_params = connection.ops.datetime_cast_date_sql(lhs, tzname)
+ lhs_params.extend(tz_params)
+ return sql, lhs_params
+
+
class DecimalField(Field):
empty_strings_allowed = False
default_error_messages = {