Skip to main content

Permission

The permissions system provides a way to assign permissions to specific users and groups of users.

Attributes

AttributeTypeDescription
namestringHuman-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.
codenamestringThe 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

NameTypeDescription
*argsanyPositional arguments passed to the model constructor.
**kwargsanyKeyword 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

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

TypeDescription
tupleA tuple containing the codename, app label, and model name.