Я хочу сделать случайный уникальный идентификатор и проверить, если он существует, то нужно сделать новый и сохранить в админ-панели модели пользователя. Заранее спасибо

Я пытался сохранить случайный account_id в User id модели django User. **** мой код ****


from .models import *
from django.contrib.auth import get_user_model
User = get_user_model()

def User():
    def account_id():
        account_id = random.randint(1000000, 9999999)
        is_unique = User.objects.filter(account_id=account_id).exists()
        if not User.account_id:
            is_unique = False
            while not is_unique:
                account_id
            User.account_id = account_id
            User.save()
        else:
            account_id()  
    account_id()          
User.save()            
      ```
Вернуться на верх