Django extension for creating forms that vary according to user permissions. It allows you to define forms where certain fields are shown or omitted based on the user's permissions. This library is currently at version 0.1 and has an active development cadence.
pip install django-permissionedformsVerified import paths — ran on the pinned version, not inferred.
To create a permissioned form, subclass either `PermissionedForm` or `PermissionedModelForm`. Define an inner `Meta` class and set `field_permissions` as a dictionary mapping field names to Django permission codenames (e.g., 'app_label.codename'). Instantiate the form by passing the `for_user` keyword argument with a Django user object. Fields for which the user lacks permission will be omitted from the form.
Monitor GitHub releases and changelogs. Pin exact dependency versions (e.g., `django-permissionedforms==0.1`).
Verify that custom permissions are defined in an app's `models.py` or through migrations. Ensure the user has the expected permissions via `user.has_perm('app_label.codename')`. Check `settings.py` for `AUTHENTICATION_BACKENDS` if custom permission logic is involved.If `FancyForm` has a custom metaclass, define a new metaclass like `class FancyPermissionedFormMetaclass(PermissionedFormMetaclass, FancyFormMetaclass): pass` and use it in your combined form: `class FancyPermissionedForm(PermissionedForm, FancyForm, metaclass=FancyPermissionedFormMetaclass): pass`.
Install the package using pip: `pip install django-permissionedforms`. Ensure your import statement is `from permissionedforms import PermissionedForm` or `from permissionedforms import PermissionedModelForm`.
After validating the form with `form.is_valid()`, access the field's data using `form.cleaned_data['field_name']` or `form.cleaned_data.get('field_name')`.When instantiating your form, ensure you pass the `for_user` keyword argument with the current request's user object: `form = MyPermissionedForm(for_user=request.user)`.