Войдите на страницу администратора Django с именем пользователя UUID

Я создал DRF api с моделью Account, идентифицированной UUID. Я также использую этот UUID в качестве имени пользователя и, таким образом, должен войти на страницу администратора, указав UUID и пароль. Однако если я попытаюсь это сделать, то получу ошибку

“6c3fe924-1848-483a-8685-c5b095f1” is not a valid UUID.

Что очень странно, поскольку это создано с помощью UUID.uuid4. Моя модель Account выглядит следующим образом

class Account(AbstractBaseUser, PermissionsMixin):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    date_joined = models.DateTimeField(default=timezone.now)
    USERNAME_FIELD = 'id'

    objects = AccountManager()

    def __str__(self):
        return str(self.id)

На AccountManager() ссылается пользовательский менеджер, поскольку эта Account модель связана с различными типами пользовательских моделей. Код для этого таков

 class AccountManager(BaseUserManager):
    def create_user(self, password, UUID=None, is_superuser=False):
        """
        Create and save a User with the given UUID and password.
        """

        if UUID is not None:
            user = self.model(id=UUID, is_superuser=is_superuser)
        else:
            user = self.model(is_superuser=is_superuser)

        user.set_password(password)
        user.save()
        return user

    def create_superuser(self, password, UUID=None, **extra_fields):
        """
        Create and save a SuperUser with the given UUID and password.
        """
        extra_fields.setdefault('is_superuser', True)
        # extra_fields.setdefault('is_active', True)


        if extra_fields.get('is_superuser') is not True:
            raise ValueError(_('Superuser must have is_superuser=True.'))
        if UUID is None:
            return self.create_user(password, is_superuser=True)
        return self.create_user(password, UUID=UUID, is_superuser=True)

Добавлю, что все те вещи, где вы можете передать значение для UUID, в настоящее время не используются. В настоящее время я создаю суперпользователей только с помощью

Account.objects.create_superuser(password="password")
Вернуться на верх