mirror of
https://github.com/django/django.git
synced 2025-10-09 14:59:24 +00:00
Fixed #36616 -- Added DatabaseOperations.adapt_durationfield_value().
This commit is contained in:
parent
b67a36ec6f
commit
1acb00b26d
@ -9,6 +9,7 @@ from django.conf import settings
|
||||
from django.db import NotSupportedError, transaction
|
||||
from django.db.models.expressions import Col
|
||||
from django.utils import timezone
|
||||
from django.utils.duration import duration_microseconds
|
||||
from django.utils.encoding import force_str
|
||||
|
||||
|
||||
@ -564,6 +565,16 @@ class BaseDatabaseOperations:
|
||||
return None
|
||||
return str(value)
|
||||
|
||||
def adapt_durationfield_value(self, value):
|
||||
"""
|
||||
Transform a timedelta value into an object compatible with what is
|
||||
expected by the backend driver for duration columns (by default,
|
||||
an integer of microseconds).
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
return duration_microseconds(value)
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
"""
|
||||
Transform a time value to an object compatible with what is expected
|
||||
|
@ -608,6 +608,9 @@ END;
|
||||
|
||||
return Oracle_datetime.from_datetime(value)
|
||||
|
||||
def adapt_durationfield_value(self, value):
|
||||
return value
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
|
@ -330,6 +330,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
def adapt_datetimefield_value(self, value):
|
||||
return value
|
||||
|
||||
def adapt_durationfield_value(self, value):
|
||||
return value
|
||||
|
||||
def adapt_timefield_value(self, value):
|
||||
return value
|
||||
|
||||
|
@ -30,7 +30,7 @@ from django.utils.dateparse import (
|
||||
parse_duration,
|
||||
parse_time,
|
||||
)
|
||||
from django.utils.duration import duration_microseconds, duration_string
|
||||
from django.utils.duration import duration_string
|
||||
from django.utils.functional import Promise, cached_property
|
||||
from django.utils.ipv6 import MAX_IPV6_ADDRESS_LENGTH, clean_ipv6_address
|
||||
from django.utils.text import capfirst
|
||||
@ -1890,11 +1890,7 @@ class DurationField(Field):
|
||||
)
|
||||
|
||||
def get_db_prep_value(self, value, connection, prepared=False):
|
||||
if connection.features.has_native_duration_field:
|
||||
return value
|
||||
if value is None:
|
||||
return None
|
||||
return duration_microseconds(value)
|
||||
return connection.ops.adapt_durationfield_value(value)
|
||||
|
||||
def get_db_converters(self, connection):
|
||||
converters = []
|
||||
|
@ -243,7 +243,9 @@ Database backend API
|
||||
This section describes changes that may be needed in third-party database
|
||||
backends.
|
||||
|
||||
* ...
|
||||
* The ``DatabaseOperations.adapt_durationfield_value()`` hook is added. If the
|
||||
database has native support for ``DurationField``, override this method to
|
||||
simply return the value.
|
||||
|
||||
Miscellaneous
|
||||
-------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user