Add the fields and methods necessary to support the Group and Permission
models using the ModelBackend.
Attributes
| Attribute | Type | Description |
|---|
| is_superuser | boolean = False | Designates 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to check permissions against |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to check permissions against |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to check permissions against |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to check permissions against |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to filter permissions for |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| obj | object = null | The specific model instance to filter permissions for |
Returns
| Type | Description |
|---|
set | A 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
| Name | Type | Description |
|---|
| perm | string | The permission string to check (e.g., 'app_label.permission_codename') |
| obj | object = null | The specific model instance to check the permission against |
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
See has_perm()
Parameters
| Name | Type | Description |
|---|
| perm | string | The permission string to check (e.g., 'app_label.permission_codename') |
| obj | object = null | The specific model instance to check the permission against |
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
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
| Name | Type | Description |
|---|
| perm_list | iterable | An iterable of permission strings to verify |
| obj | object = null | The specific model instance to check all permissions against |
Returns
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| perm_list | iterable | An iterable of permission strings to verify |
| obj | object = null | The specific model instance to check all permissions against |
Returns
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| app_label | string | The label of the application to check for permissions |
Returns
| Type | Description |
|---|
boolean | True 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
| Name | Type | Description |
|---|
| app_label | string | The label of the application to check for permissions |
Returns
| Type | Description |
|---|
boolean | True if the user has at least one permission in the specified app |