Category Api lari tayyor

This commit is contained in:
2025-11-24 15:57:46 +05:00
parent b0ad0ea173
commit 37a16900f7
17 changed files with 199 additions and 14 deletions

41
test.py Normal file
View File

@@ -0,0 +1,41 @@
import random
from core.apps.api.models import Category
def generate_categories(total=150):
Category.objects.all().delete()
created = []
queue = []
# 1) Root level: 35 ta
root_count = random.randint(3, 5)
for i in range(root_count):
cat = Category.objects.create(name=f"Category {len(created) + 1}")
created.append(cat)
queue.append(cat)
# 2) Qolganlarini yaratamiz
while len(created) < total:
if not queue:
break
parent = queue.pop(0)
# Har bir parentga 13 ta bola
children_count = random.randint(1, 3)
for _ in range(children_count):
if len(created) >= total:
break
child = Category.objects.create(
name=f"Category {len(created) + 1}",
parent=parent,
)
created.append(child)
# bola yana parent bo'lishi mumkin — shuning uchun queue ga qoshamiz
queue.append(child)
return f"{len(created)} ta category yaratildi!"