diff --git a/add_tenant_with_prefix.py b/add_tenant_with_prefix.py index 6f20d53..73124f6 100644 --- a/add_tenant_with_prefix.py +++ b/add_tenant_with_prefix.py @@ -205,7 +205,7 @@ class CreateTenant(Script): except Exception as e: self.log_failure(f"Ошибка при создании контакта: {e}") try: - role = data.get("contacts_role", ContactRole.objects.first()) + role = data.get("contacts_role") or ContactRole.objects.first() assignment = ContactAssignment( contact=contact, role=role, @@ -242,9 +242,10 @@ class CreateTenant(Script): email=data["contacts_email"], ) contact.full_clean() + role = data.get("contacts_role") or ContactRole.objects.first() assignment = ContactAssignment( contact=contact, - role=data.get("contacts_role", ContactRole.objects.first()), + role=role, object=tenant, ) assignment.full_clean()