Given an OGR Feature, the related model and its dictionary mapping, retrieve the related model for the ForeignKey mapping.
(self, feat, rel_model, rel_mapping)
| 462 | return val |
| 463 | |
| 464 | def verify_fk(self, feat, rel_model, rel_mapping): |
| 465 | """ |
| 466 | Given an OGR Feature, the related model and its dictionary mapping, |
| 467 | retrieve the related model for the ForeignKey mapping. |
| 468 | """ |
| 469 | # TODO: It is expensive to retrieve a model for every record -- |
| 470 | # explore if an efficient mechanism exists for caching related |
| 471 | # ForeignKey models. |
| 472 | |
| 473 | # Constructing and verifying the related model keyword arguments. |
| 474 | fk_kwargs = {} |
| 475 | for field_name, ogr_name in rel_mapping.items(): |
| 476 | fk_kwargs[field_name] = self.verify_ogr_field( |
| 477 | feat[ogr_name], rel_model._meta.get_field(field_name) |
| 478 | ) |
| 479 | |
| 480 | # Attempting to retrieve and return the related model. |
| 481 | try: |
| 482 | return rel_model.objects.using(self.using).get(**fk_kwargs) |
| 483 | except ObjectDoesNotExist: |
| 484 | raise MissingForeignKey( |
| 485 | "No ForeignKey %s model found with keyword arguments: %s" |
| 486 | % (rel_model.__name__, fk_kwargs) |
| 487 | ) |
| 488 | |
| 489 | def verify_geom(self, geom, model_field): |
| 490 | """ |
no test coverage detected