You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) -
fromdjango.core.exceptionsimportPermissionDeniedclassMyModelAdmin(InlineActionsModelAdminMixin, admin.modelAdmin):
...
defget_inline_actions(self, request, obj=None):
actions=super().get_inline_actions(request, obj)
ifobjandself.has_change_permission(request, obj): # check if user has object change permissionifobj.status==Article.PUBLISHED:
actions.append('unpublish')
returnactionsdefunpublish(self, request, obj, inline_obj=None):
ifnotobjornotself.has_change_permission(request, obj): # check if user has object change permissionraisePermissionDenied()
obj.status=Article.DRAFTobj.save()
self.log_change(request, obj, "Article unpublished") # add the unpublish action to object's historymessages.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.
The text was updated successfully, but these errors were encountered:
Basically, when a particular inline action is carried out on a given model's entry, we should
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) -
Above checks if user has basic change permission on the object & also logs the unpublish action in the object's admin history.
The text was updated successfully, but these errors were encountered: