Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notes &/or functionality to keep admin history of actions carried out #31

Open
ashishnitinpatil opened this issue Feb 17, 2020 · 0 comments

Comments

@ashishnitinpatil
Copy link
Contributor

ashishnitinpatil commented Feb 17, 2020

Basically, when a particular inline action is carried out on a given model's entry, we should

  1. suggest to register the inline action inside django admin's history
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants