پرش به محتویات

مجوزها

اینکه یک مدل مجوزهایش را چطور اعلام می‌کند، و اینکه هر کدی چطور بدون هجی کردن اسم یک مجوز به آن اشاره می‌کند. توضیح‌های زیر از خود کد خوانده می‌شوند، و مثل کد به انگلیسی‌اند.

build_permissions

build_permissions(codename: str, resource: str | Promise, *, actions: Iterable[str] = DEFAULT_ACTIONS, labels: Mapping[str, str | Promise] | None = None, protected_fields: Iterable[str] = (), status_actions: Mapping[str, StatusDeclaration] | None = None) -> DeclaredPermissions

Meta.permissions for one resource.

build_permissions('loan', 'loans') gives loan_view, loan_create, loan_edit and loan_delete. labels names an action in words of its own - {'approve': _('Can approve or decline %(resource)s')}. protected_fields=('rate',) adds loan_view_rate and loan_edit_rate. status_actions={'approve': {'field': 'status', 'to': ['approved']}} adds the action approve, which alone writes approved.

DeclaredPermissions

Bases: tuple[tuple[str, str], ...]

Meta.permissions as build_permissions makes it: the (codename, name) pairs Django reads, and what they were made from - the resource's codename and its protected fields - for the library to read back.

adding

adding(codename: str, label: Promise) -> DeclaredPermissions

These, and one permission more that no action of the resource names - stored by its English name, as Django stores every permission's, and read in the reader's language.

permission_for

permission_for(model: type[Model] | Model, action: str, *, codename: str | None = None) -> str

The permission action on model needs, as app_label.codename.

A model keeping Django's permissions answers in Django's style - shop.change_order for edit; a model that declares its own answers in the library's - shop.order_edit. Listing is viewing. An action beyond the four is <codename>_<action> either way. codename names the resource when it is not the model's own name.

DEFAULT_ACTIONS module-attribute

DEFAULT_ACTIONS: Final = ('view', 'create', 'edit', 'delete')