Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-russell committed Feb 26, 2024
1 parent 7cb5c28 commit 8164790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fractal_database_matrix/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.2 on 2024-02-16 22:59
# Generated by Django 5.0.2 on 2024-02-22 21:00

import django.db.models.deletion
from django.db import migrations, models
Expand Down
18 changes: 15 additions & 3 deletions fractal_database_matrix/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,26 @@ async def create_representation(self, repr_log: "RepresentationLog", target_id:
"""
Creates a Matrix space for the ReplicatedModel "instance" that inherits from this class
"""
model_class = repr_log.content_type.model_class()
# get the model the object that this representation log is for
# (this is usually a ReplicationTarget model since only ReplicationTargets can create representations)
model_class: "MatrixReplicationTarget" = repr_log.content_type.model_class() # type: ignore
# get the model for the target that this representation log is for
target_model = repr_log.target_type.model_class()
# fetch the replicated model that this representation log is for
instance = await model_class.objects.aget(pk=repr_log.object_id)
target = await target_model.objects.prefetch_related("matrixcredentials_set").aget(
# fetch the target
target: "MatrixReplicationTarget" = await target_model.objects.prefetch_related(
"matrixcredentials_set"
).aget(
pk=target_id
)
) # type: ignore

# pull room ids from metadata
parent_room_id = target.metadata["room_id"]
child_room_id = instance.metadata["room_id"]
if parent_room_id == child_room_id:
raise Exception("Parent and child room IDs cannot be the same")

await self.add_subspace(target, parent_room_id, child_room_id)


Expand Down

0 comments on commit 8164790

Please sign in to comment.