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

Django REST framework

کلاس‌های مجوز، mixinهای serializer و viewsetها - هر کدام به تنهایی، روی هر view در DRF. توضیح‌های زیر از خود کد خوانده می‌شوند، و مثل کد به انگلیسی‌اند.

ModelPolicyPermission

Bases: PolicyPermission

Asks the policy of the view's model - from queryset, or get_queryset().

PolicyPermission

Bases: BasePermission

Asks the policy the view names in policy.

policy_for_view classmethod

policy_for_view(view: type[APIView] | APIView) -> BasePolicy | None

The policy asked for view, read off its class - None when it names none.

refuse_writes staticmethod

refuse_writes(request: Request, policy: BasePolicy, obj: Model | None, view: object = None) -> None

A 400 naming every field the request sends that the person may not write - by the model field each name writes: decision, sent to a serializer whose field has source='status', is the status.

ProtectedFieldsSerializerMixin

Leaves out, locks and refuses what the person may not read or write.

protected_for property

protected_for: User

Whose serializer this is: the request's person, or context['user'].

build_nested_field

build_nested_field(*args: Any, **kwargs: Any) -> Any

A serializer depth makes for a related row protects that row's fields too.

create

create(validated_data: Any) -> Any

The row made, refused and undone when it is outside the scope of create.

update

update(instance: Any, validated_data: Any) -> Any

The row changed, refused and undone when it is moved out of the rows reached.

many_init classmethod

many_init(*args: Any, **kwargs: Any) -> Any

A list of these, saved in one transaction: a row refused undoes the rows before it.

protected_serializer cached

protected_serializer(serializer_class: type[Any]) -> type[Any]

serializer_class with ProtectedFieldsSerializerMixin - made once per class. A serializer of no model is returned as it is: its writes are the permission class's to guard.

ScopedModelViewSet

Bases: ProtectedSerializerMixin, ScopedQuerySetMixin, ModelViewSet

A ModelViewSet asking the model's policy, over the rows the person reaches.

ScopedReadOnlyViewSet

Bases: ProtectedSerializerMixin, ScopedQuerySetMixin, ReadOnlyModelViewSet

A ReadOnlyModelViewSet asking the model's policy, over the rows the person reaches.