Refs #2443 -- Move the durationfield converter logic.
This reduces how frequently this logic is run significantly. Thanks to Anssi for the suggestion.
This commit is contained in:
parent
5ca82e710e
commit
962bb9b6bd
|
@ -1262,8 +1262,6 @@ class BaseDatabaseOperations(object):
|
||||||
Some field types on some backends do not provide data in the correct
|
Some field types on some backends do not provide data in the correct
|
||||||
format, this is the hook for coverter functions.
|
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 []
|
return []
|
||||||
|
|
||||||
def convert_durationfield_value(self, value, field):
|
def convert_durationfield_value(self, value, field):
|
||||||
|
|
|
@ -1614,6 +1614,12 @@ class DurationField(Field):
|
||||||
return value
|
return value
|
||||||
return value.total_seconds() * 1000000
|
return value.total_seconds() * 1000000
|
||||||
|
|
||||||
|
def get_db_converters(self, connection):
|
||||||
|
converters = []
|
||||||
|
if not connection.features.has_native_duration_field:
|
||||||
|
converters.append(connection.ops.convert_durationfield_value)
|
||||||
|
return converters + super(DurationField, self).get_db_converters(connection)
|
||||||
|
|
||||||
def value_to_string(self, obj):
|
def value_to_string(self, obj):
|
||||||
val = self._get_val_from_obj(obj)
|
val = self._get_val_from_obj(obj)
|
||||||
return '' if val is None else duration_string(val)
|
return '' if val is None else duration_string(val)
|
||||||
|
|
Loading…
Reference in New Issue