Fixed #25673 -- Made `GeometryField.from_db_value` set SRID
This commit is contained in:
parent
f98126a05a
commit
5f7035cec7
|
@ -257,8 +257,12 @@ class GeometryField(GeoSelectFormatMixin, BaseSpatialField):
|
||||||
return geom
|
return geom
|
||||||
|
|
||||||
def from_db_value(self, value, expression, connection, context):
|
def from_db_value(self, value, expression, connection, context):
|
||||||
if value and not isinstance(value, Geometry):
|
if value:
|
||||||
|
if not isinstance(value, Geometry):
|
||||||
value = Geometry(value)
|
value = Geometry(value)
|
||||||
|
srid = value.srid
|
||||||
|
if not srid and self.srid != -1:
|
||||||
|
value.srid = self.srid
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_srid(self, geom):
|
def get_srid(self, geom):
|
||||||
|
|
|
@ -893,3 +893,7 @@ class GeoQuerySetTest(TestCase):
|
||||||
def test_non_concrete_field(self):
|
def test_non_concrete_field(self):
|
||||||
NonConcreteModel.objects.create(point=Point(0, 0), name='name')
|
NonConcreteModel.objects.create(point=Point(0, 0), name='name')
|
||||||
list(NonConcreteModel.objects.all())
|
list(NonConcreteModel.objects.all())
|
||||||
|
|
||||||
|
def test_values_srid(self):
|
||||||
|
for c, v in zip(City.objects.all(), City.objects.values()):
|
||||||
|
self.assertEqual(c.point.srid, v['point'].srid)
|
||||||
|
|
Loading…
Reference in New Issue