Skip to main content

PermissionsMixin

Add the fields and methods necessary to support the Group and Permission models using the ModelBackend.

Attributes

AttributeTypeDescription
is_superuserboolean = FalseDesignates that this user has all permissions without explicitly assigning them.
groups[ManyToManyField](../../../db/models/fields/related/manytomanyfield.md?sid=django_db_models_fields_related_manytomanyfield)The groups this user belongs to. A user will get all permissions granted to each of their groups.
user_permissions[ManyToManyField](../../../db/models/fields/related/manytomanyfield.md?sid=django_db_models_fields_related_manytomanyfield)Specific permissions for this user.

Methods


get_user_permissions()

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

Return a list of permission strings that this user has directly. Query all available auth backends. If an object is passed in, return only permissions matching this object.

Parameters

NameTypeDescription
objobject = nullThe specific model instance to check permissions against

Returns

TypeDescription
setA set of permission strings granted directly to the user

aget_user_permissions()

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

See get_user_permissions()

Parameters

NameTypeDescription
objobject = nullThe specific model instance to check permissions against

Returns

TypeDescription
setA set of permission strings granted directly to the user

get_group_permissions()

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

Return a list of permission strings that this user has through their groups. Query all available auth backends. If an object is passed in, return only permissions matching this object.

Parameters

NameTypeDescription
objobject = nullThe specific model instance to check permissions against

Returns

TypeDescription
setA set of permission strings inherited from the user's groups

aget_group_permissions()

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

See get_group_permissions()

Parameters

NameTypeDescription
objobject = nullThe specific model instance to check permissions against

Returns

TypeDescription
setA set of permission strings inherited from the user's groups

get_all_permissions()

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

Fetches the complete set of permission strings the user possesses, including both direct and group-based permissions.

Parameters

NameTypeDescription
objobject = nullThe specific model instance to filter permissions for

Returns

TypeDescription
setA set of all permission strings the user has access to

aget_all_permissions()

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

Asynchronously fetches the complete set of permission strings the user possesses, including both direct and group-based permissions.

Parameters

NameTypeDescription
objobject = nullThe specific model instance to filter permissions for

Returns

TypeDescription
setA set of all permission strings the user has access to

has_perm()

@classmethod
def has_perm(
perm: string,
obj: object = null
) - > boolean

Return True if the user has the specified permission. Query all available auth backends, but return immediately if any backend returns True. Thus, a user who has permission from a single auth backend is assumed to have permission in general. If an object is provided, check permissions for that object.

Parameters

NameTypeDescription
permstringThe permission string to check (e.g., 'app_label.permission_codename')
objobject = nullThe specific model instance to check the permission against

Returns

TypeDescription
booleanTrue if the user has the permission, False otherwise

ahas_perm()

@classmethod
def ahas_perm(
perm: string,
obj: object = null
) - > boolean

See has_perm()

Parameters

NameTypeDescription
permstringThe permission string to check (e.g., 'app_label.permission_codename')
objobject = nullThe specific model instance to check the permission against

Returns

TypeDescription
booleanTrue if the user has the permission, False otherwise

has_perms()

@classmethod
def has_perms(
perm_list: iterable,
obj: object = null
) - > boolean

Return True if the user has each of the specified permissions. If object is passed, check if the user has all required perms for it.

Parameters

NameTypeDescription
perm_listiterableAn iterable of permission strings to verify
objobject = nullThe specific model instance to check all permissions against

Returns

TypeDescription
booleanTrue if the user has all listed permissions, False otherwise

ahas_perms()

@classmethod
def ahas_perms(
perm_list: iterable,
obj: object = null
) - > boolean

See has_perms()

Parameters

NameTypeDescription
perm_listiterableAn iterable of permission strings to verify
objobject = nullThe specific model instance to check all permissions against

Returns

TypeDescription
booleanTrue if the user has all listed permissions, False otherwise

has_module_perms()

@classmethod
def has_module_perms(
app_label: string
) - > boolean

Return True if the user has any permissions in the given app label. Use similar logic as has_perm(), above.

Parameters

NameTypeDescription
app_labelstringThe label of the application to check for permissions

Returns

TypeDescription
booleanTrue if the user has at least one permission in the specified app

ahas_module_perms()

@classmethod
def ahas_module_perms(
app_label: string
) - > boolean

See has_module_perms()

Parameters

NameTypeDescription
app_labelstringThe label of the application to check for permissions

Returns

TypeDescription
booleanTrue if the user has at least one permission in the specified app