AbstractUser
An abstract base class implementing a fully featured User model with admin-compliant permissions.
Attributes
| Attribute | Type | Description |
|---|---|---|
| username_validator | validator = UnicodeUsernameValidator() | Validator instance used to ensure the username contains only letters, digits, and @/./+/-/_ characters. |
| username | string | Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. |
| first_name | string | Optional first name of the user with a maximum length of 150 characters. |
| last_name | string | Optional last name of the user with a maximum length of 150 characters. |
email address | Optional email address for the user used for communications and identification. | |
| is_staff | boolean = False | Designates whether the user can log into this admin site. |
| is_active | boolean = True | Designates whether this user should be treated as active. Unselect this instead of deleting accounts. |
| date_joined | datetime = timezone.now | The 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_FIELD | string = "email" | The name of the field that stores the user's email address. |
| USERNAME_FIELD | string = "username" | The name of the field used as the unique identifier for the user. |
| REQUIRED_FIELDS | list = ["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
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list. |
| **kwargs | any | Arbitrary 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
| Type | Description |
|---|---|
null | Nothing 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
| Type | Description |
|---|---|
string | The 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
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| subject | string | The subject line of the email. |
| message | string | The body text of the email message. |
| from_email | string = null | The sender's email address; defaults to the system's DEFAULT_FROM_EMAIL if not provided. |
| **kwargs | dict | Additional keyword arguments passed directly to the underlying send_mail function. |
Returns
| Type | Description |
|---|---|
null | Nothing is returned; the email is dispatched via the configured mail backend. |