사용자 이름을 고유하게 만드는 논리에 약간의 도움이 필요합니다.django - 사용자의 고유 이름 만들기
저는 장고 사용자 프로필을 가지고 있습니다. 나는이 방법으로 사용자를 만드는 오전 :
fullname = request.POST.get('fullname')
random_username = ''.join(random.sample(string.ascii_lowercase, 8))
new_user = User.objects.create_user(random_username, email, passwort)
##update siteprofile of this new user
userprofile = new_user.get_profile()
"""
i need to make this fullname unique with this logic:
for example john is the fullname of new user. i need to check if there are
other johns in db, if there is another user with this name, i will name the
user with 'john1'. if there are 2, the new user will get the name 'john3'
how can I check this in db in some efficient way?
"""
userprofile.name = fullname
userprofile.save()
아주 좋은데, 이것은 세계의 두 부분에서 두 사람이 똑같은 이름을 설정하지 않았는지 확인합니다. – doniyor
맞습니다. 그리고 db 레벨을 수행하므로 두 스레드가 동시에 같은 이름을 설정하는 경우가 거의 없습니다. – sdolan
''userprofile.fullname = fullname''는''userprofile.fullname = new_fullname''이어야합니다, 맞습니까? – doniyor