Skip to main content

PermissionManager

This class provides custom manager functionality for handling permission objects within a database. It includes specialized support for retrieving permissions using natural keys, facilitating data serialization and migrations across different environments.

Attributes

AttributeTypeDescription
use_in_migrationsboolean = TrueA boolean flag indicating that this manager should be available during data migrations to ensure permission logic is accessible.

Methods


get_by_natural_key()

@classmethod
def get_by_natural_key(
codename: string,
app_label: string,
model: string
) - > [Permission](permission.md?sid=django_contrib_auth_models_permission)

Fetches a permission instance using its natural key components, which uniquely identify a permission across different database installations.

Parameters

NameTypeDescription
codenamestringThe unique programmatic name of the permission, such as 'add_user' or 'change_message'.
app_labelstringThe name of the application the model belongs to, used to locate the correct ContentType.
modelstringThe name of the specific model class associated with the permission.

Returns

TypeDescription
[Permission](permission.md?sid=django_contrib_auth_models_permission)The Permission object matching the specified codename and model content type.