Skip to main content

AnonymousUser

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

AttributeTypeDescription
idnull = nullUnique identifier for the user, which is always None as anonymous users are not persisted in the database.
pknull = nullPrimary key alias for the user identifier, consistently returning None for unauthenticated users.
usernamestringThe login name for the user, which defaults to an empty string for anonymous instances.
is_staffboolean = falseBoolean flag indicating whether the user has access to the admin site, always False for anonymous users.
is_activeboolean = falseBoolean flag indicating whether the user account is considered active, always False for anonymous users.
is_superuserboolean = falseBoolean flag indicating that the user has all permissions without explicitly assigning them, always False for anonymous users.

Methods


save()

@classmethod
def save()

Raises a NotImplementedError because anonymous users do not have a database representation.


delete()

@classmethod
def 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

NameTypeDescription
raw_passwordstringThe 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

NameTypeDescription
raw_passwordstringThe 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

TypeDescription
[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

TypeDescription
[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

NameTypeDescription
objobject = nullAn optional object to check permissions against for object-level authorization.

Returns

TypeDescription
setA 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

NameTypeDescription
objobject = nullAn optional object to check permissions against for object-level authorization.

Returns

TypeDescription
setA 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

NameTypeDescription
objobject = nullAn optional object to check group permissions against.

Returns

TypeDescription
setAn empty set.

aget_group_permissions()

@classmethod
def aget_group_permissions(
obj: object = null
) - > set

Asynchronously returns an empty set of group permissions.

Parameters

NameTypeDescription
objobject = nullAn optional object to check group permissions against.

Returns

TypeDescription
setAn 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

NameTypeDescription
objobject = nullAn optional object to check permissions against.

Returns

TypeDescription
setA 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

NameTypeDescription
objobject = nullAn optional object to check permissions against.

Returns

TypeDescription
setA 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

NameTypeDescription
permstringThe permission string to check (e.g., 'app_label.permission_codename').
objobject = nullAn optional object for object-level permission checking.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
permstringThe permission string to check.
objobject = nullAn optional object for object-level permission checking.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
perm_listiterableAn iterable of permission strings to check.
objobject = nullAn optional object for object-level permission checking.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
perm_listiterableAn iterable of permission strings to check.
objobject = nullAn optional object for object-level permission checking.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
modulestringThe app_label of the module to check.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
modulestringThe app_label of the module to check.

Returns

TypeDescription
booleanTrue if the user has permissions in the module, False otherwise.

is_anonymous()

@classmethod
def is_anonymous() - > boolean

Indicates whether the user is anonymous.

Returns

TypeDescription
booleanAlways returns True.

is_authenticated()

@classmethod
def is_authenticated() - > boolean

Indicates whether the user is authenticated.

Returns

TypeDescription
booleanAlways returns False.

get_username()

@classmethod
def get_username() - > string

Fetches the username associated with the anonymous user.

Returns

TypeDescription
stringAn empty string representing the anonymous username.