Skip to main content

BaseUserManager

This class provides a base implementation for managing user models, offering utility methods for handling common authentication tasks. It includes functionality for normalizing email addresses and retrieving user instances via natural keys in both synchronous and asynchronous contexts.

Methods


normalize_email()

@classmethod
def normalize_email(
email: string
) - > string

Normalize the email address by lowercasing the domain part of it.

Parameters

NameTypeDescription
emailstringThe raw email address string to be normalized

Returns

TypeDescription
stringThe normalized email address with the domain portion converted to lowercase

get_by_natural_key()

@classmethod
def get_by_natural_key(
username: string
) - > [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)

Fetches a user instance using the field defined as the unique identifier on the user model.

Parameters

NameTypeDescription
usernamestringThe value of the field defined by USERNAME_FIELD used to uniquely identify the user

Returns

TypeDescription
[Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)The user instance associated with the provided natural key

aget_by_natural_key()

@classmethod
def aget_by_natural_key(
username: string
) - > [Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)

Asynchronously fetches a user instance using the field defined as the unique identifier on the user model.

Parameters

NameTypeDescription
usernamestringThe value of the field defined by USERNAME_FIELD used to uniquely identify the user

Returns

TypeDescription
[Model](../../../../db/models/base/model.md?sid=django_db_models_base_model)A coroutine that resolves to the user instance associated with the provided natural key