diff -r 64ec0b7000d1 django/contrib/gis/utils/layermapping.py
a
|
b
|
|
393 | 393 | |
394 | 394 | # Attempting to retrieve and return the related model. |
395 | 395 | try: |
396 | | return rel_model.objects.get(**fk_kwargs) |
| 396 | return rel_model.objects.using(self.using).get(**fk_kwargs) |
397 | 397 | except ObjectDoesNotExist: |
398 | 398 | raise MissingForeignKey('No ForeignKey %s model found with keyword arguments: %s' % (rel_model.__name__, fk_kwargs)) |
399 | 399 | |
… |
… |
|
429 | 429 | SpatialRefSys = self.spatial_backend.spatial_ref_sys() |
430 | 430 | try: |
431 | 431 | # Getting the target spatial reference system |
432 | | target_srs = SpatialRefSys.objects.get(srid=self.geo_field.srid).srs |
| 432 | target_srs = SpatialRefSys.objects.using(self.using).get(srid=self.geo_field.srid).srs |
433 | 433 | |
434 | 434 | # Creating the CoordTransform object |
435 | 435 | return CoordTransform(self.source_srs, target_srs) |
diff -r 64ec0b7000d1 django/contrib/gis/utils/srs.py
a
|
b
|
|
1 | 1 | from django.contrib.gis.gdal import SpatialReference |
2 | | from django.db import connections, DEFAULT_DB_ALIAS |
3 | 2 | |
4 | 3 | def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, |
5 | | database=DEFAULT_DB_ALIAS): |
| 4 | database=None): |
6 | 5 | """ |
7 | 6 | This function takes a GDAL SpatialReference system and adds its information |
8 | 7 | to the `spatial_ref_sys` table of the spatial backend. Doing this enables |
… |
… |
|
33 | 32 | of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value |
34 | 33 | is 'default'). |
35 | 34 | """ |
| 35 | from django.db import connections, DEFAULT_DB_ALIAS |
| 36 | if not database: |
| 37 | database = DEFAULT_DB_ALIAS |
36 | 38 | connection = connections[database] |
| 39 | |
37 | 40 | if not hasattr(connection.ops, 'spatial_version'): |
38 | 41 | raise Exception('The `add_srs_entry` utility only works ' |
39 | 42 | 'with spatial backends.') |
… |
… |
|
69 | 72 | try: |
70 | 73 | # Try getting via SRID only, because using all kwargs may |
71 | 74 | # differ from exact wkt/proj in database. |
72 | | sr = SpatialRefSys.objects.get(srid=srs.srid) |
| 75 | sr = SpatialRefSys.objects.using(database).get(srid=srs.srid) |
73 | 76 | except SpatialRefSys.DoesNotExist: |
74 | | sr = SpatialRefSys.objects.create(**kwargs) |
| 77 | sr = SpatialRefSys.objects.using(database).create(**kwargs) |
75 | 78 | |
76 | 79 | # Alias is for backwards-compatibility purposes. |
77 | 80 | add_postgis_srs = add_srs_entry |