phase3: add normalized domain schema, admin, services, and multistage docker build
This commit is contained in:
0
apps/providers/services/__init__.py
Normal file
0
apps/providers/services/__init__.py
Normal file
19
apps/providers/services/mappings.py
Normal file
19
apps/providers/services/mappings.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from apps.providers.models import ExternalMapping
|
||||
|
||||
|
||||
def upsert_external_mapping(*, provider_namespace: str, external_id: str, instance, raw_payload: dict | None = None) -> ExternalMapping:
|
||||
"""Create or update a provider mapping for any internal model instance."""
|
||||
content_type = ContentType.objects.get_for_model(instance.__class__)
|
||||
mapping, _ = ExternalMapping.objects.update_or_create(
|
||||
provider_namespace=provider_namespace,
|
||||
content_type=content_type,
|
||||
object_id=instance.pk,
|
||||
defaults={
|
||||
"external_id": external_id,
|
||||
"raw_payload": raw_payload or {},
|
||||
"is_active": True,
|
||||
},
|
||||
)
|
||||
return mapping
|
||||
Reference in New Issue
Block a user