diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-07-24 13:57:24 +0100 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-12-20 18:28:29 +0000 |
| commit | 57554442fe3e209c135e15dda4ea45123e579e58 (patch) | |
| tree | 0ef2cb0e3048d13b82e4c7e81192df6124556a44 /django/db/backends/__init__.py | |
| parent | a3d96bee36040975ded8e3bf02e33e48d06f1f16 (diff) | |
Fixed #2443 -- Added DurationField.
A field for storing periods of time - modeled in Python by timedelta. It
is stored in the native interval data type on PostgreSQL and as a bigint
of microseconds on other backends.
Also includes significant changes to the internals of time related maths
in expressions, including the removal of DateModifierNode.
Thanks to Tim and Josh in particular for reviews.
Diffstat (limited to 'django/db/backends/__init__.py')
| -rw-r--r-- | django/db/backends/__init__.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index bdf841cbd9..104744b220 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1,5 +1,6 @@ from collections import deque import datetime +import decimal import time import warnings @@ -18,6 +19,7 @@ from django.db.backends.signals import connection_created from django.db.backends import utils from django.db.transaction import TransactionManagementError from django.db.utils import DatabaseError, DatabaseErrorWrapper, ProgrammingError +from django.utils.dateparse import parse_duration from django.utils.deprecation import RemovedInDjango19Warning from django.utils.functional import cached_property from django.utils import six @@ -575,6 +577,9 @@ class BaseDatabaseFeatures(object): supports_binary_field = True + # Is there a true datatype for timedeltas? + has_native_duration_field = False + # Do time/datetime fields have microsecond precision? supports_microsecond_precision = True @@ -1251,8 +1256,16 @@ class BaseDatabaseOperations(object): Some field types on some backends do not provide data in the correct format, this is the hook for coverter functions. """ + if not self.connection.features.has_native_duration_field and internal_type == 'DurationField': + return [self.convert_durationfield_value] return [] + def convert_durationfield_value(self, value, field): + if value is not None: + value = str(decimal.Decimal(value) / decimal.Decimal(1000000)) + value = parse_duration(value) + return value + def check_aggregate_support(self, aggregate_func): """Check that the backend supports the provided aggregate @@ -1272,6 +1285,9 @@ class BaseDatabaseOperations(object): conn = ' %s ' % connector return conn.join(sub_expressions) + def combine_duration_expression(self, connector, sub_expressions): + return self.combine_expression(connector, sub_expressions) + def modify_insert_params(self, placeholders, params): """Allow modification of insert parameters. Needed for Oracle Spatial backend due to #10888. |
