{"id":2001,"library":"django-permissionedforms","title":"Django Permissioned Forms","description":"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.","status":"active","version":"0.1","language":"en","source_language":"en","source_url":"https://github.com/wagtail/django-permissionedforms","tags":["django","forms","permissions","authorization","wagtail"],"install":[{"cmd":"pip install django-permissionedforms","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core framework dependency, forms are built on Django's forms framework. Requires Django 3.7+ (implied by Python 3.7+ requirement and Django 5.2+ seen in distribution metadata).","package":"Django","optional":false}],"imports":[{"symbol":"PermissionedForm","correct":"from permissionedforms import PermissionedForm"},{"symbol":"PermissionedModelForm","correct":"from permissionedforms import PermissionedModelForm"}],"quickstart":{"code":"from django import forms\nfrom permissionedforms import PermissionedForm, PermissionedModelForm\n\n# Example 1: Basic Form\nclass PersonForm(PermissionedForm):\n    first_name = forms.CharField(max_length=100)\n    last_name = forms.CharField(max_length=100)\n\n    class Meta:\n        field_permissions = {\n            'last_name': 'myapp.change_last_name_field'\n        }\n\n# Example 2: Model Form\n# from django.db import models\n# class Country(models.Model):\n#    name = models.CharField(max_length=100)\n#    description = models.TextField(blank=True)\n#    class Meta:\n#        app_label = 'myapp'\n#        permissions = [('change_country_description', 'Can change country description')]\n\n# class CountryForm(PermissionedModelForm):\n#    class Meta:\n#        model = Country\n#        fields = ['name', 'description']\n#        field_permissions = {\n#            'description': 'myapp.change_country_description'\n#        }\n\n# Usage in a view (assuming 'request' is an HttpRequest object)\n# user = request.user # A Django User object\n# form = PersonForm(for_user=user)\n# if form.is_valid():\n#    pass\n\n# model_instance = Country.objects.first() # or create one\n# model_form = CountryForm(instance=model_instance, for_user=user)","lang":"python","description":"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."},"warnings":[{"fix":"Monitor GitHub releases and changelogs. Pin exact dependency versions (e.g., `django-permissionedforms==0.1`).","message":"As this library is at version 0.1, the API is still considered unstable. Future minor or major versions may introduce breaking changes without extensive deprecation cycles. Users should pin exact versions and review release notes carefully for upgrades.","severity":"breaking","affected_versions":"0.1.x"},{"fix":"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.","message":"Incorrect configuration of Django's native permission system (e.g., missing permissions, misnamed codenames, or improper `AUTHENTICATION_BACKENDS`) can lead to fields being unexpectedly hidden or shown. Ensure your permissions are correctly defined and applied to users/groups.","severity":"gotcha","affected_versions":"0.1.x"},{"fix":"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`.","message":"When integrating `PermissionedForm` or `PermissionedModelForm` with another custom base form class that defines its own metaclass, direct multiple inheritance might fail. A custom metaclass inheriting from both `PermissionedFormMetaclass` and the other form's metaclass may be required.","severity":"gotcha","affected_versions":"0.1.x"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}