(backend) add django-treebeard to allow tree structure on documents

We choose to use Django-treebeard for its quality, performance and
stability. Adding tree structure to documents is as simple as
inheriting from the MP_Node class.
This commit is contained in:
Samuel Paccoud - DINUM
2024-12-16 16:58:14 +01:00
committed by Anthony LC
parent 0189078917
commit 276b4f7c1b
12 changed files with 208 additions and 12 deletions

View File

@@ -287,7 +287,7 @@ class ServerCreateDocumentSerializer(serializers.Serializer):
{"content": ["Could not convert content"]}
) from err
document = models.Document.objects.create(
document = models.Document.add_root(
title=validated_data["title"],
content=document_content,
creator=user,

View File

@@ -431,7 +431,11 @@ class DocumentViewSet(
def perform_create(self, serializer):
"""Set the current user as creator and owner of the newly created object."""
obj = serializer.save(creator=self.request.user)
obj = models.Document.add_root(
creator=self.request.user,
**serializer.validated_data,
)
serializer.instance = obj
models.DocumentAccess.objects.create(
document=obj,
user=self.request.user,