mirror of
https://github.com/django/django.git
synced 2025-11-30 23:38:10 +00:00
Complete rework of translating data values from database Deprecation of SubfieldBase, removal of resolve_columns and convert_values in favour of a more general converter based approach and public API Field.from_db_value(). Now works seamlessly with aggregation, .values() and raw queries. Thanks to akaariai in particular for extensive advice and inspiration, also to shaib, manfre and timograham for their reviews.
This commit is contained in:
parent
89559bcfb0
commit
e9103402c0
35 changed files with 443 additions and 521 deletions
|
|
@ -54,15 +54,6 @@ class RawQuery(object):
|
|||
def clone(self, using):
|
||||
return RawQuery(self.sql, using, params=self.params)
|
||||
|
||||
def convert_values(self, value, field, connection):
|
||||
"""Convert the database-returned value into a type that is consistent
|
||||
across database backends.
|
||||
|
||||
By default, this defers to the underlying backend operations, but
|
||||
it can be overridden by Query classes for specific backends.
|
||||
"""
|
||||
return connection.ops.convert_values(value, field)
|
||||
|
||||
def get_columns(self):
|
||||
if self.cursor is None:
|
||||
self._execute_query()
|
||||
|
|
@ -308,15 +299,6 @@ class Query(object):
|
|||
obj._setup_query()
|
||||
return obj
|
||||
|
||||
def convert_values(self, value, field, connection):
|
||||
"""Convert the database-returned value into a type that is consistent
|
||||
across database backends.
|
||||
|
||||
By default, this defers to the underlying backend operations, but
|
||||
it can be overridden by Query classes for specific backends.
|
||||
"""
|
||||
return connection.ops.convert_values(value, field)
|
||||
|
||||
def resolve_aggregate(self, value, aggregate, connection):
|
||||
"""Resolve the value of aggregates returned by the database to
|
||||
consistent (and reasonable) types.
|
||||
|
|
@ -337,7 +319,13 @@ class Query(object):
|
|||
return float(value)
|
||||
else:
|
||||
# Return value depends on the type of the field being processed.
|
||||
return self.convert_values(value, aggregate.field, connection)
|
||||
backend_converters = connection.ops.get_db_converters(aggregate.field.get_internal_type())
|
||||
field_converters = aggregate.field.get_db_converters(connection)
|
||||
for converter in backend_converters:
|
||||
value = converter(value, aggregate.field)
|
||||
for converter in field_converters:
|
||||
value = converter(value, connection)
|
||||
return value
|
||||
|
||||
def get_aggregation(self, using, force_subq=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue