Permission
The permissions system provides a way to assign permissions to specific users and groups of users.
Attributes
| Attribute | Type | Description |
|---|---|---|
| name | string | Human-readable display name for the permission, such as 'Can add poll'. |
| content_type | [ForeignKey](../../../db/models/fields/related/foreignkey.md?sid=django_db_models_fields_related_foreignkey) | A reference to the ContentType model representing the specific type of object this permission applies to. |
| codename | string | The internal programmatic identifier used for permission checks, such as 'add_poll'. |
| objects | [PermissionManager](permissionmanager.md?sid=django_contrib_auth_models_permissionmanager) | The manager instance providing database query operations for Permission models. |
Constructor
Signature
def Permission(
*args: any,
**kwargs: any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Positional arguments passed to the model constructor. |
| **kwargs | any | Keyword arguments representing field values such as name, content_type, and codename. |
Methods
user_perm_str()
@classmethod
def user_perm_str() - > string
String representation for the user permission check.
Returns
| Type | Description |
|---|---|
string | The dot-separated permission string in the format 'app_label.codename' used by Django's authorization backend. |
natural_key()
@classmethod
def natural_key() - > tuple
Generates a tuple that uniquely identifies the permission without using a primary key, facilitating serialization across different databases.
Returns
| Type | Description |
|---|---|
tuple | A tuple containing the codename, app label, and model name. |