Currently, in django.contrib.auth, there can be two users with the username ‘john’ and ‘John’. How can I prevent this from happening.
The most straightforward approach is add a clean method in contib.auth.models and convert it to a lowercase before saving but i dont want to edit the contrib.auth package.
Thanks.
Listen on
pre_savefor theUsersmodel and then do your checks there. Least intrusive and most portable way.Here is an example on how this would look like (adapted from the user profile example):