import os import sys import django # Добавляем путь к проекту sys.path.insert(0, 'C:/Users/team_/Desktop/test_qwen/myproject') # Настройка Django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') django.setup() from tenants.models import TenantRegistration, Client from django.contrib.auth import get_user_model from django.db import connection from tenants.admin import TenantRegistrationAdmin import uuid # Уникальное имя unique_id = str(uuid.uuid4())[:8] schema_name = f'test_{unique_id}' # Создаём новую заявку registration = TenantRegistration.objects.create( shop_name='Fresh Test', schema_name=schema_name, owner_email='fresh@example.com', owner_name='Fresh User', phone='+375291234567', status=TenantRegistration.STATUS_PENDING ) print(f"\n=== Testing Fresh Superuser Creation ===") print(f"Schema: {schema_name}\n") # Получаем админа из public public_tenant = Client.objects.get(schema_name='public') connection.set_tenant(public_tenant) User = get_user_model() admin_user = User.objects.first() # Одобряем заявку admin = TenantRegistrationAdmin(TenantRegistration, None) try: print("Approving registration...") client = admin._approve_registration(registration, admin_user) print("Approval completed!\n") # Переключаемся в новый тенант connection.set_tenant(client) # Проверим пользователей all_users = User.objects.all().order_by('email') print(f"All users in {client.schema_name} schema ({all_users.count()} total):") for u in all_users: status = "SUPERUSER" if u.is_superuser else "regular" print(f" - {u.email} ({u.name}) [{status}]") if not all_users.exists(): print(" NO USERS FOUND - THIS IS A PROBLEM!") except Exception as e: print(f"ERROR: {str(e)}") import traceback traceback.print_exc()