diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index 12be7682ed..80fe8628ce 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -257,8 +257,12 @@ class GeometryField(GeoSelectFormatMixin, BaseSpatialField): return geom def from_db_value(self, value, expression, connection, context): - if value and not isinstance(value, Geometry): - value = Geometry(value) + if value: + if not isinstance(value, Geometry): + value = Geometry(value) + srid = value.srid + if not srid and self.srid != -1: + value.srid = self.srid return value def get_srid(self, geom): diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py index 53b5b5bc28..9c8b3f7a8d 100644 --- a/tests/gis_tests/geoapp/tests.py +++ b/tests/gis_tests/geoapp/tests.py @@ -893,3 +893,7 @@ class GeoQuerySetTest(TestCase): def test_non_concrete_field(self): NonConcreteModel.objects.create(point=Point(0, 0), name='name') 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)