fix(blog): limit category nesting depth

This commit is contained in:
2026-06-12 21:35:04 +03:30
parent 9acab4af2c
commit 690dc7b600

View File

@@ -343,10 +343,14 @@ def _validate_category_parent(category_id: int | None, parent_id: int | None) ->
return None, None return None, None
if category_id and parent_id == category_id: if category_id and parent_id == category_id:
return None, "A category cannot be its own parent." return None, "A category cannot be its own parent."
if category_id and Category.objects.filter(parent_id=category_id).exists():
return None, "A category with child categories must remain a root category."
parent = Category.objects.filter(id=parent_id).first() parent = Category.objects.filter(id=parent_id).first()
if not parent: if not parent:
return None, "Parent category not found." return None, "Parent category not found."
if parent.parent_id:
return None, "Only root categories can be selected as a parent."
current = parent current = parent
seen: set[int] = set() seen: set[int] = set()