Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, change username

Tags:

python

django

Is it possible to change the username?

I tried the following :-

user = User.objects.get(username = username)
user.username = newusername
user.save()

Nothing changes

I can change the username in the admin screen, but there are more than 100 where the client asked for different usernames to be used.

like image 999
jimscafe Avatar asked Jan 16 '13 09:01

jimscafe


1 Answers

As you note (Django, change username), this was a mistake in your code - the code sample did not reflect your code. The code sample posted will in fact work to change a User object's username:

user = User.objects.get(username = username)
user.username = newusername
user.save()
like image 144
Marcin Avatar answered Oct 26 '22 19:10

Marcin