Skip to main content

AbstractUser

An abstract base class implementing a fully featured User model with admin-compliant permissions.

Attributes

AttributeTypeDescription
username_validatorvalidator = UnicodeUsernameValidator()Validator instance used to ensure the username contains only letters, digits, and @/./+/-/_ characters.
usernamestringRequired. 150 characters or fewer. Letters, digits and @/./+/-/_ only.
first_namestringOptional first name of the user with a maximum length of 150 characters.
last_namestringOptional last name of the user with a maximum length of 150 characters.
emailemail addressOptional email address for the user used for communications and identification.
is_staffboolean = FalseDesignates whether the user can log into this admin site.
is_activeboolean = TrueDesignates whether this user should be treated as active. Unselect this instead of deleting accounts.
date_joineddatetime = timezone.nowThe date and time the user account was created.
objects[UserManager](usermanager.md?sid=django_contrib_auth_models_usermanager) = UserManager()The manager instance providing database query operations for the User model.
EMAIL_FIELDstring = "email"The name of the field that stores the user's email address.
USERNAME_FIELDstring = "username"The name of the field used as the unique identifier for the user.
REQUIRED_FIELDSlist = ["email"]A list of field names that will be prompted for when creating a user via the createsuperuser management command.

Constructor

Signature

def AbstractUser(
*args: any,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*argsanyVariable length argument list.
**kwargsanyArbitrary keyword arguments representing model fields and values.

Methods


clean()

@classmethod
def clean() - > null

Normalizes the user's email address by applying the model manager's normalization logic during the model validation process.

Returns

TypeDescription
nullNothing is returned; the instance state is modified in place.

get_full_name()

@classmethod
def get_full_name() - > string

Return the first_name plus the last_name, with a space in between.

Returns

TypeDescription
stringThe combined first and last name of the user, stripped of leading or trailing whitespace.

get_short_name()

@classmethod
def get_short_name() - > string

Return the short name for the user.

Returns

TypeDescription
stringThe user's first name.

email_user()

@classmethod
def email_user(
subject: string,
message: string,
from_email: string = null,
**kwargs: dict
) - > null

Send an email to this user.

Parameters

NameTypeDescription
subjectstringThe subject line of the email.
messagestringThe body text of the email message.
from_emailstring = nullThe sender's email address; defaults to the system's DEFAULT_FROM_EMAIL if not provided.
**kwargsdictAdditional keyword arguments passed directly to the underlying send_mail function.

Returns

TypeDescription
nullNothing is returned; the email is dispatched via the configured mail backend.