Code

Ticket #17018: layermapping.patch

File layermapping.patch, 909 bytes (added by grobertson, 3 years ago)
  • 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                try: 
     299                    val = self.verify_fk(feat, model_field, ogr_name) 
     300                except MissingForeignKey, mfk: 
     301                    if self.model._meta.get_field(field_name).null: 
     302                        val = None 
     303                    else: 
     304                        raise mfk 
    299305            else: 
    300306                # Otherwise, verify OGR Field type. 
    301307                val = self.verify_ogr_field(feat[ogr_name], model_field)