From 39baccb0b167984137dad469ffd25b918b583bbf Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Fri, 29 Nov 2024 10:24:48 +0100 Subject: [PATCH] feat(utils): update create_object_from_uri to work with generic uri The `Uri` model now uses a generic foreign key instead of the direct foreign key to the `RootObject`. This commit updates all occurences of `root_object` to use the generic foreign key instead. --- apis_core/utils/helpers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apis_core/utils/helpers.py b/apis_core/utils/helpers.py index a65f83e48..275a08823 100644 --- a/apis_core/utils/helpers.py +++ b/apis_core/utils/helpers.py @@ -75,12 +75,17 @@ def create_object_from_uri(uri: str, model: object, raise_on_fail=False) -> obje if uri.startswith("http"): try: uri = Uri.objects.get(uri=uri) - return uri.root_object + return uri.content_object except Uri.DoesNotExist: Importer = get_importer_for_model(model) importer = Importer(uri, model) instance = importer.create_instance() - uri = Uri.objects.create(uri=importer.get_uri, root_object=instance) + content_type = ContentType.objects.get_for_model(instance) + uri = Uri.objects.create( + uri=importer.get_uri, + content_type=content_type, + object_id=instance.id, + ) return instance if raise_on_fail: content_type = ContentType.objects.get_for_model(model)