Ticket #17018: django-17018.diff
| File django-17018.diff, 5.5 KB (added by , 15 years ago) |
|---|
-
django/contrib/gis/utils/layermapping.py
295 295 elif isinstance(model_field, models.base.ModelBase): 296 296 # The related _model_, not a field was passed in -- indicating 297 297 # another mapping for the related Model. 298 val = self.verify_fk(feat, model_field, ogr_name) 298 fk_field = self.model._meta.get_field(field_name) 299 val = self.verify_fk(feat, model_field, fk_field, ogr_name) 299 300 else: 300 301 # Otherwise, verify OGR Field type. 301 302 val = self.verify_ogr_field(feat[ogr_name], model_field) … … 373 374 val = ogr_field.value 374 375 return val 375 376 376 def verify_fk(self, feat, rel_model, rel_mapping):377 def verify_fk(self, feat, rel_model, rel_mapping): 377 378 """ 378 379 Given an OGR Feature, the related model and its dictionary mapping, 379 380 this routine will retrieve the related model for the ForeignKey … … 385 386 386 387 # Constructing and verifying the related model keyword arguments. 387 388 fk_kwargs = {} 389 388 390 for field_name, ogr_name in rel_mapping.items(): 391 389 392 fk_kwargs[field_name] = self.verify_ogr_field(feat[ogr_name], rel_model._meta.get_field(field_name)) 390 393 394 395 396 397 398 399 391 400 # Attempting to retrieve and return the related model. 392 401 try: 393 402 return rel_model.objects.using(self.using).get(**fk_kwargs) -
django/contrib/gis/tests/layermap/tests.py
11 11 from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey 12 12 13 13 from .models import ( 14 City, County, County Feat, Interstate, ICity1, ICity2, Invalid, State,14 City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State, 15 15 city_mapping, co_mapping, cofeat_mapping, inter_mapping) 16 16 17 17 18 18 shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data')) 19 19 city_shp = os.path.join(shp_path, 'cities', 'cities.shp') 20 20 co_shp = os.path.join(shp_path, 'counties', 'counties.shp') 21 21 22 inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp') 22 23 invalid_shp = os.path.join(shp_path, 'invalid', 'emptypoints.shp') 23 24 … … 26 27 NUMS = [1, 2, 1, 19, 1] # Number of polygons for each. 27 28 STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado'] 28 29 30 29 31 class LayerMapTest(TestCase): 30 32 31 33 def test01_init(self): … … 278 280 lm = LayerMapping(Invalid, invalid_shp, invalid_mapping, 279 281 source_srs=4326) 280 282 lm.save(silent=True) 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 -
django/contrib/gis/tests/layermap/models.py
10 10 mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83 11 11 objects = models.GeoManager() 12 12 13 14 15 16 17 18 13 19 class CountyFeat(models.Model): 14 20 name = models.CharField(max_length=25) 15 21 poly = models.PolygonField(srid=4269)