Skip to content

Commit

Permalink
feat(utils): update create_object_from_uri to work with generic uri
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b1rger committed Dec 20, 2024
1 parent 87fdb98 commit f7d71ae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apis_core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7d71ae

Please sign in to comment.