These actions will appear at the top of the changelist page as buttons. Please not that these actions are not displayed in the actions dropdown which is provided by default in Django. Changelist action will not reciver any queryset or object ids, because it is meant to be used for general actions for given model.
# admin.py
from django.contrib.admin import register
from django.contrib.auth.models import User
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.http import HttpRequest
from unfold.admin import ModelAdmin
from unfold.decorators import action
@register(User)
class UserAdmin(ModelAdmin):
actions_list = ["changelist_action"]
@action(description=_("Changelist action"), url_path="changelist-action")
def changelist_action(self, request: HttpRequest, permissions=["changelist_action"]):
return redirect(
reverse_lazy("admin:users_user_changelist")
)
def has_changelist_action_permission(self, request: HttpRequest):
pass
Django admin theme built with Tailwind CSS to bring modern look and feel to your admin interface. Already contains several built-in features for smooth developer experience.
© 2023 - 2024 Created by unfoldadmin.com. All rights reserved.