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
| Attribute | Type | Description |
|---|---|---|
| use_in_migrations | boolean = True | A 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
| Name | Type | Description |
|---|---|---|
| codename | string | The unique programmatic name of the permission, such as 'add_user' or 'change_message'. |
| app_label | string | The name of the application the model belongs to, used to locate the correct ContentType. |
| model | string | The name of the specific model class associated with the permission. |
Returns
| Type | Description |
|---|---|
[Permission](permission.md?sid=django_contrib_auth_models_permission) | The Permission object matching the specified codename and model content type. |