Open
Description
Basically, when a particular inline action is carried out on a given model's entry, we should
- suggest to register the inline action inside django admin's history
- suggest to check if user has correct permissions to carry out said inline action
Suggestions can be in just the README &/or the demo app. Also, if these could be incorporated into a functionality or feature somehow, that would be great.
Example action function with admin history (based on ModelAdmin docs) -
from django.core.exceptions import PermissionDenied
class MyModelAdmin(InlineActionsModelAdminMixin, admin.modelAdmin):
...
def get_inline_actions(self, request, obj=None):
actions = super().get_inline_actions(request, obj)
if obj and self.has_change_permission(request, obj): # check if user has object change permission
if obj.status == Article.PUBLISHED:
actions.append('unpublish')
return actions
def unpublish(self, request, obj, inline_obj=None):
if not obj or not self.has_change_permission(request, obj): # check if user has object change permission
raise PermissionDenied()
obj.status = Article.DRAFT
obj.save()
self.log_change(request, obj, "Article unpublished") # add the unpublish action to object's history
messages.info(request, _("Article unpublished"))
unpublish.short_description = _("Unpublish")
Above checks if user has basic change permission on the object & also logs the unpublish action in the object's admin history.