MCPcopy
hub / github.com/django/django / verify_fk

Method verify_fk

django/contrib/gis/utils/layermapping.py:464–487  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 1

feature_kwargsMethod · 0.95

Calls 6

verify_ogr_fieldMethod · 0.95
MissingForeignKeyClass · 0.85
itemsMethod · 0.45
get_fieldMethod · 0.45
getMethod · 0.45
usingMethod · 0.45

Tested by

no test coverage detected