This class represents a non-authenticated user and provides a compatible interface with the standard user model. It implements core authentication properties and permission-checking methods, though it lacks a database representation and cannot be saved or deleted. All instances are considered unauthenticated and anonymous by default.
Attributes
| Attribute | Type | Description |
|---|
| id | null = null | Unique identifier for the user, which is always None as anonymous users are not persisted in the database. |
| pk | null = null | Primary key alias for the user identifier, consistently returning None for unauthenticated users. |
| username | string | The login name for the user, which defaults to an empty string for anonymous instances. |
| is_staff | boolean = false | Boolean flag indicating whether the user has access to the admin site, always False for anonymous users. |
| is_active | boolean = false | Boolean flag indicating whether the user account is considered active, always False for anonymous users. |
| is_superuser | boolean = false | Boolean flag indicating that the user has all permissions without explicitly assigning them, always False for anonymous users. |
Methods
save()
Raises a NotImplementedError because anonymous users do not have a database representation.
delete()
Raises a NotImplementedError because anonymous users cannot be deleted from the database.
set_password()
@classmethod
def set_password(
raw_password: string
)
Raises a NotImplementedError because anonymous users do not support password persistence.
Parameters
| Name | Type | Description |
|---|
| raw_password | string | The plain-text password that would be set. |
check_password()
@classmethod
def check_password(
raw_password: string
)
Raises a NotImplementedError because anonymous users do not have a stored password to verify against.
Parameters
| Name | Type | Description |
|---|
| raw_password | string | The plain-text password to verify. |
groups()
@classmethod
def groups() - > [EmptyManager](../../../db/models/manager/emptymanager.md?sid=django_db_models_manager_emptymanager)
Provides access to an empty manager representing the groups associated with the user.
Returns
| Type | Description |
|---|
[EmptyManager](../../../db/models/manager/emptymanager.md?sid=django_db_models_manager_emptymanager) | An empty manager instance for Group objects. |
user_permissions()
@classmethod
def user_permissions() - > [EmptyManager](../../../db/models/manager/emptymanager.md?sid=django_db_models_manager_emptymanager)
Provides access to an empty manager representing the specific permissions assigned to the user.
Returns
| Type | Description |
|---|
[EmptyManager](../../../db/models/manager/emptymanager.md?sid=django_db_models_manager_emptymanager) | An empty manager instance for Permission objects. |
get_user_permissions()
@classmethod
def get_user_permissions(
obj: object = null
) - > set
Fetches the set of permission strings that the user has directly.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check permissions against for object-level authorization. |
Returns
| Type | Description |
|---|
set | A set of permission strings. |
aget_user_permissions()
@classmethod
def aget_user_permissions(
obj: object = null
) - > set
Asynchronously fetches the set of permission strings that the user has directly.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check permissions against for object-level authorization. |
Returns
| Type | Description |
|---|
set | A set of permission strings. |
get_group_permissions()
@classmethod
def get_group_permissions(
obj: object = null
) - > set
Returns an empty set because anonymous users cannot belong to groups.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check group permissions against. |
Returns
| Type | Description |
|---|
set | An empty set. |
aget_group_permissions()
@classmethod
def aget_group_permissions(
obj: object = null
) - > set
Asynchronously returns an empty set of group permissions.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check group permissions against. |
Returns
| Type | Description |
|---|
set | An empty set. |
get_all_permissions()
@classmethod
def get_all_permissions(
obj: object = null
) - > set
Fetches the combined set of all permissions available to the user.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check permissions against. |
Returns
| Type | Description |
|---|
set | A set of all permission strings. |
aget_all_permissions()
@classmethod
def aget_all_permissions(
obj: object = null
) - > set
Asynchronously fetches the combined set of all permissions available to the user.
Parameters
| Name | Type | Description |
|---|
| obj | object = null | An optional object to check permissions against. |
Returns
| Type | Description |
|---|
set | A set of all permission strings. |
has_perm()
@classmethod
def has_perm(
perm: string,
obj: object = null
) - > boolean
Checks if the user has a specific permission.
Parameters
| Name | Type | Description |
|---|
| perm | string | The permission string to check (e.g., 'app_label.permission_codename'). |
| obj | object = null | An optional object for object-level permission checking. |
Returns
| Type | Description |
|---|
boolean | True if the user has the permission, False otherwise. |
ahas_perm()
@classmethod
def ahas_perm(
perm: string,
obj: object = null
) - > boolean
Asynchronously checks if the user has a specific permission.
Parameters
| Name | Type | Description |
|---|
| perm | string | The permission string to check. |
| obj | object = null | An optional object for object-level permission checking. |
Returns
| Type | Description |
|---|
boolean | True if the user has the permission, False otherwise. |
has_perms()
@classmethod
def has_perms(
perm_list: iterable,
obj: object = null
) - > boolean
Checks if the user has all of the specified permissions.
Parameters
| Name | Type | Description |
|---|
| perm_list | iterable | An iterable of permission strings to check. |
| obj | object = null | An optional object for object-level permission checking. |
Returns
| Type | Description |
|---|
boolean | True if the user has every permission in the list, False otherwise. |
ahas_perms()
@classmethod
def ahas_perms(
perm_list: iterable,
obj: object = null
) - > boolean
Asynchronously checks if the user has all of the specified permissions.
Parameters
| Name | Type | Description |
|---|
| perm_list | iterable | An iterable of permission strings to check. |
| obj | object = null | An optional object for object-level permission checking. |
Returns
| Type | Description |
|---|
boolean | True if the user has every permission in the list, False otherwise. |
has_module_perms()
@classmethod
def has_module_perms(
module: string
) - > boolean
Checks if the user has any permissions within a specific application module.
Parameters
| Name | Type | Description |
|---|
| module | string | The app_label of the module to check. |
Returns
| Type | Description |
|---|
boolean | True if the user has permissions in the module, False otherwise. |
ahas_module_perms()
@classmethod
def ahas_module_perms(
module: string
) - > boolean
Asynchronously checks if the user has any permissions within a specific application module.
Parameters
| Name | Type | Description |
|---|
| module | string | The app_label of the module to check. |
Returns
| Type | Description |
|---|
boolean | True if the user has permissions in the module, False otherwise. |
is_anonymous()
@classmethod
def is_anonymous() - > boolean
Indicates whether the user is anonymous.
Returns
| Type | Description |
|---|
boolean | Always returns True. |
is_authenticated()
@classmethod
def is_authenticated() - > boolean
Indicates whether the user is authenticated.
Returns
| Type | Description |
|---|
boolean | Always returns False. |
get_username()
@classmethod
def get_username() - > string
Fetches the username associated with the anonymous user.
Returns
| Type | Description |
|---|
string | An empty string representing the anonymous username. |