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

فیلدها و مقدارها

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

readable_fields

readable_fields(user: User, model: type[Model]) -> frozenset[str]

The fields of model user may read: every field but the protected ones they lack.

writable_fields

writable_fields(user: User, model: type[Model]) -> frozenset[str]

The fields of model user may write: what they read, less what they may not edit.

path_readable

path_readable(user: User, model: type[Model], path: str) -> bool

Whether a lookup - region, applicant__region, -amount - reads only fields user may read. Searching, filtering or ordering by a field tells somebody what it holds as surely as showing it.

field_permissions

field_permissions(model: type[Model], name: str) -> dict[str, str]

{'view': ..., 'edit': ...} - the two permissions of model.name.

writable_values

writable_values(user: User, model: type[Model], field: str, obj: Model | None = None) -> frozenset[Any]

The values of field user may write to obj - or to a new row.

Nothing when they may not write the field; every value for the superuser. Otherwise every value no status action claims, the value the row holds already - keeping it is no change - and the values of every action claiming them that they are allowed, from where the row stands.

require_within_scope

require_within_scope(user: User, action: str, obj: Model) -> None

PermissionDenied unless obj, as it is saved now, is among the rows user reaches for action.

Asked after the row is written and inside the transaction that wrote it, so the refusal undoes the write: a row made outside the scope create was given in, or edited out of the scope edit was.

require_deletable

require_deletable(user: User, rows: Model | Iterable[Model]) -> None

PermissionDenied unless deleting rows - a row, or several - takes only rows user may delete: those rows, and every row a cascade would take with them.

Asked before the delete. A row deleted with another is deleted all the same, so somebody allowed to delete a loan but no payment would otherwise delete its payments. Every model a cascade reaches that has a delete permission is asked for it, within its scope. What has none to ask - a table Django makes for a many-to-many field, the library's own tables - and what Django keeps for itself - its admin site's log, its sessions and content types - goes as Django sends it.