我已经创建了一个自定义管理操作。我在多个列表页面中使用该操作。
在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列表页面中,它都显示为"My custom action for x“。有没有办法更改"X“=> "Y”for Y列表页面。
或
如何在不为每个模型编写自定义方法的情况下,在djagno中重命名单个列表页面的custom_action名称。
发布于 2021-07-16 15:07:57
试试这个:
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'
https://stackoverflow.com/questions/68404505
复制相似问题