Ticket #17018: django-17018.diff

File django-17018.diff, 5.5 KB (added by Glen Robertson, 15 years ago)

updated patch with tests

  • django/contrib/gis/utils/layermapping.py

     
    295295            elif isinstance(model_field, models.base.ModelBase):
    296296                # The related _model_, not a field was passed in -- indicating
    297297                # 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)
    299300            else:
    300301                # Otherwise, verify OGR Field type.
    301302                val = self.verify_ogr_field(feat[ogr_name], model_field)
     
    373374            val = ogr_field.value
    374375        return val
    375376
    376     def verify_fk(self, feat, rel_model, rel_mapping):
     377    def verify_fk(self, feat, rel_model, rel_mapping):
    377378        """
    378379        Given an OGR Feature, the related model and its dictionary mapping,
    379380        this routine will retrieve the related model for the ForeignKey
     
    385386
    386387        # Constructing and verifying the related model keyword arguments.
    387388        fk_kwargs = {}
     389
    388390        for field_name, ogr_name in rel_mapping.items():
     391
    389392            fk_kwargs[field_name] = self.verify_ogr_field(feat[ogr_name], rel_model._meta.get_field(field_name))
    390393
     394
     395
     396
     397
     398
     399
    391400        # Attempting to retrieve and return the related model.
    392401        try:
    393402            return rel_model.objects.using(self.using).get(**fk_kwargs)
  • django/contrib/gis/tests/layermap/tests.py

     
    1111from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey
    1212
    1313from .models import (
    14     City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State,
     14    City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State,
    1515    city_mapping, co_mapping, cofeat_mapping, inter_mapping)
    1616
    1717
    1818shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data'))
    1919city_shp = os.path.join(shp_path, 'cities', 'cities.shp')
    2020co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
     21
    2122inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp')
    2223invalid_shp = os.path.join(shp_path, 'invalid', 'emptypoints.shp')
    2324
     
    2627NUMS   = [1, 2, 1, 19, 1] # Number of polygons for each.
    2728STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
    2829
     30
    2931class LayerMapTest(TestCase):
    3032
    3133    def test01_init(self):
     
    278280        lm = LayerMapping(Invalid, invalid_shp, invalid_mapping,
    279281                          source_srs=4326)
    280282        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

     
    1010    mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83
    1111    objects = models.GeoManager()
    1212
     13
     14
     15
     16
     17
     18
    1319class CountyFeat(models.Model):
    1420    name = models.CharField(max_length=25)
    1521    poly = models.PolygonField(srid=4269)
Back to Top