Added BaseSpatialField.get_db_prep_value() to simplify.

BaseSpatialField.get_db_prep_value() supersedes
BaseSpatialField.get_db_prep_save() and Geometry.get_db_prep_value().
This commit is contained in:
Sergey Fedoseev 2017-07-20 22:26:22 +05:00
parent c19b56f633
commit 8d5095d8a3
1 changed files with 6 additions and 13 deletions

View File

@ -155,14 +155,13 @@ class BaseSpatialField(Field):
else: else:
return srid return srid
def get_db_prep_save(self, value, connection): def get_db_prep_value(self, value, connection, *args, **kwargs):
""" if value is None:
Prepare the value for saving in the database.
"""
if isinstance(value, Geometry) or value:
return connection.ops.Adapter(self.get_prep_value(value))
else:
return None return None
return connection.ops.Adapter(
super().get_db_prep_value(value, connection, *args, **kwargs),
**({'geography': True} if self.geography and connection.ops.geography else {})
)
def get_raster_prep_value(self, value, is_candidate): def get_raster_prep_value(self, value, is_candidate):
""" """
@ -256,12 +255,6 @@ class GeometryField(GeoSelectFormatMixin, BaseSpatialField):
kwargs['geography'] = self.geography kwargs['geography'] = self.geography
return name, path, args, kwargs return name, path, args, kwargs
def get_db_prep_value(self, value, connection, *args, **kwargs):
return connection.ops.Adapter(
super().get_db_prep_value(value, connection, *args, **kwargs),
**({'geography': True} if self.geography else {})
)
def from_db_value(self, value, expression, connection, context): def from_db_value(self, value, expression, connection, context):
if value: if value:
value = Geometry(value) value = Geometry(value)