ReversePermissionPolicy¶
- class django_admin_reversefields.mixins.ReversePermissionPolicy(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for checking reverse relation modification permissions.
Policies may be provided as callable objects or as objects exposing a
has_permmethod. The mixin callshas_permif present before falling back to calling the object itself, so implementations can opt into either style. Policy objects may providepermission_denied_messageto customise validation errors.Example:
class StaffOnlyPolicy: permission_denied_message = "Staff access required" def __call__(self, request, obj, config, selection): return getattr(request.user, "is_staff", False)
- permission_denied_message: str | None = None¶
Optional error message to display on the field when permission checks fail during form validation.
This message will be shown to users when __call__ returns False, helping them understand why they cannot modify the reverse relation.