I thought this code for insert automatically id in username field. This method should be used in save method. This code work on a dbms that support transactions ( example: mysql+innodb or postgresql ).
Let me know what you think about this snippet and if you advice an alternative solution by commenting below.
1 2 3 4 5 6
def create_new_user(self, username, email, password): new_user = User.objects.create_user(username, email, password) new_user.username = str(new_user.id) new_user.save() return new_user create_new_user = transaction.commit_on_success(create_new_user)
More like this
- Add custom fields to the built-in Group model by jmoppel 1 month, 2 weeks ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 4 months, 4 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 5 months, 2 weeks ago
- Browser-native date input field by kytta 6 months, 4 weeks ago
- Generate and render HTML Table by LLyaudet 7 months, 1 week ago