#34055 closed New feature (wontfix)

InlineModelAdmin and permissions on the instances shown in the in-line

Reported by: Jonas Vacek Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords: Admin, Inline, Permissions
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.has_change_permission

As documented above, the has_{xyz}_permission() functions are referring to the parent obj.

As far as I can tell, there's no method currently available change the permissions on each instance inside of an inline.

to help visualise what I'm aiming for, here is a screenshot with an implemented work-around that overrrides the default form of the in-line

https://i.imgur.com/Aatfblj.png
The work-around is not perfect, as it just changes the <input> attributes on the form, and changes will not be rejected in any way, but it gives the visual idea. The above is achieved with the following

class MyInlineForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(MyInlineForm, self).__init__(*args, **kwargs)
        instance = getattr(self, "instance", None)
        if (
            instance
            and instance.id
            and (instance.my_permission_function())
        ):
            for field in self.fields:
                self.fields[field].widget.attrs["readonly"] = True

Change History (1)

comment:1 by Carlton Gibson, 19 months ago

Resolution: wontfix
Status: newclosed

Implementing the backend for object-level permissions is out-of-scope for Django itself. (See #29918 and linked discussions and PRs)

Third-party packages allow for this: django-guardian, django-rules, and others.

Note: See TracTickets for help on using tickets.
Back to Top