head --> root to avoid confusion, prevent root deletion

[ci skip]
This commit is contained in:
shamoon
2026-02-10 16:26:13 -08:00
parent 7fa400f486
commit 8014932419
16 changed files with 150 additions and 124 deletions

View File

@@ -308,13 +308,13 @@ class Document(SoftDeleteModel, ModelWithOwner):
),
)
head_version = models.ForeignKey(
root_document = models.ForeignKey(
"self",
blank=True,
null=True,
related_name="versions",
on_delete=models.CASCADE,
verbose_name=_("head version of document"),
verbose_name=_("root document for this version"),
)
version_label = models.CharField(
@@ -441,9 +441,9 @@ class Document(SoftDeleteModel, ModelWithOwner):
*args,
**kwargs,
):
# If deleting a head document, move all versions to trash as well.
if self.head_version_id is None:
Document.objects.filter(head_version=self).delete()
# If deleting a root document, move all its versions to trash as well.
if self.root_document_id is None:
Document.objects.filter(root_document=self).delete()
return super().delete(
*args,
**kwargs,