I had the same problem a few days ago. Finally, I ended up just disconnecting the first 30 characters of the (old) username (in the new database table) and adding my own authentication server that will check email instead of the username. A terrible hack that I know, and I plan to fix it as soon as I have time. The idea is as follows:
I already have a model class that has a one-to-one relationship with djangos auth.User. I will add another field called full_username .
class MyCustomUserModel(models.Model): user = models.OneToOneField( settings.AUTH_USER_MODEL, related_name="custom_user") full_username = models.CharField(max_length=80, ...) ...
Then I will add another user authentication server that will check this field as a username. It will look something like this:
from django.contrib.auth.backends import ModelBackend class FullUsernameAuthBackend(ModelBackend): def authenticate(self, username=None, password=None, **kwargs): UserModel = get_user_model() if username is None: username = kwargs.get(UserModel.USERNAME_FIELD) try: user = UserModel._default_manager.filter(custom_user__full_username=username)
After that you need to change settings.py:
AUTHENTICATION_BACKENDS = ( "....FullUsernameAuthBackend",
I hope this works.
source share