mirror of
https://github.com/django/django.git
synced 2025-10-25 14:46:09 +00:00
Refs #26112 -- Fixed aggregate GIS test on Oracle.
Made sure the test doesn't try to aggregate over MultiPolygonField and made AreaField turn decimals into floats on the way from the DB. Thanks Daniel Wiesmann, Jani Tiainen, and Tim Graham for review and discussion.
This commit is contained in:
@@ -4,6 +4,8 @@ database.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from django.contrib.gis.db.models.fields import GeoSelectFormatMixin
|
||||
from django.contrib.gis.geometry.backend import Geometry
|
||||
from django.contrib.gis.measure import Area, Distance
|
||||
@@ -27,6 +29,10 @@ class AreaField(BaseField):
|
||||
def from_db_value(self, value, expression, connection, context):
|
||||
if connection.features.interprets_empty_strings_as_nulls and value == '':
|
||||
value = None
|
||||
# If the database returns a Decimal, convert it to a float as expected
|
||||
# by the Python geometric objects.
|
||||
if isinstance(value, Decimal):
|
||||
value = float(value)
|
||||
# If the units are known, convert value into area measure.
|
||||
if value is not None and self.area_att:
|
||||
value = Area(**{self.area_att: value})
|
||||
|
||||
Reference in New Issue
Block a user