diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-12-23 10:11:28 +0000 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-12-23 10:41:42 +0000 |
| commit | 962bb9b6bd1deb042e139316108ec0da44cb22a9 (patch) | |
| tree | 3886b1b493416099023defcad8ad8f3e1147256a /django | |
| parent | 5ca82e710e2f92b8c5114492205c8764918407d3 (diff) | |
Refs #2443 -- Move the durationfield converter logic.
This reduces how frequently this logic is run significantly.
Thanks to Anssi for the suggestion.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/__init__.py | 2 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index eb70ad9861..b13fb1e9d5 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1262,8 +1262,6 @@ 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): diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index e8e6750f1e..6a56603359 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1614,6 +1614,12 @@ class DurationField(Field): return value 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): val = self._get_val_from_obj(obj) return '' if val is None else duration_string(val) |
