djangodjango-admin-actions

How can I create a button for a django admin action?


I have a django admin action say "refresh", I want to add a refresh button for each row in the admin list view. I can create button using format_html but how can I invoke "refresh" action when it is pressed?


Solution

  • I don't think admin actions are the best fit in this case.

    Actions are

    simple functions that get called with a list of objects selected on the change list page

    With the buttons you describe however, you want to operate on a single row/instance. Therefore I would simply create a custom url endpoint for your ModelAdmin which is called when you press the button and which handles the desired action.

    This article has quite a comprehensive overview how this can be done in detail.