问题描述
在我的 admin.py 文件中
def custom_action(request,modelAdmin,queryset):
#do something here
return response
custom_action.short_description = 'My custom action for X'
class MyXAdmin(admin.ModelAdmin):
actions = [custom_action]
class MyYAdmin(admin.ModelAdmin):
actions = [custom_action]
在我的 X 和 Y 列表页面中,它都显示“我对 x 的自定义操作”。有什么方法可以更改 Y 列表页面的“X”=>“Y”。
或
如何在不为每个模型编写自定义方法的情况下实现在 djagno 中重命名单个列表页面的 custom_action 名称。
解决方法
试试这个:
class MyXAdmin(admin.ModelAdmin):
actions = [custom_action]
custom_action.short_description = 'My custom action for X'
class MyYAdmin(admin.ModelAdmin):
actions = [custom_action]
custom_action.short_description = 'My custom action for Y'