我当前正在尝试更改“删除所选”管理操作的名称。我已经有效地覆盖了默认值(因此我可以在完全删除默认值之前存储一些数据),但是现在我想将选项从模糊的“已删除选定的注册”更改为更具体的名称,例如“已删除所有选定的注册”。或者,至少说出“删除选定的注册”,就像我重写该功能之前一样。
到目前为止,我已经尝试过:
delete_selected.short_description = 'Delete all selected registrations'
但是该选项仍然是“已删除已选择”。有办法解决这个问题吗?
这是我的代码:
def delete_selected(modeladmin, request, queryset):
"""
This overrides the defult deleted_selected because we want to gather the data from the registration and create a
DeletedRegistration object before we delete it.
"""
for registration in queryset:
reg = registration.get_registrant()
if registration.payment_delegation:
delegate_name = registration.payment_delegation.name
delegate_email = registration.payment_delegation.email
else:
delegate_name = None
delegate_email = None
registration_to_delete = DeletedRegistration.objects.create(
registrant_name = reg.full_name(),
registrant_email = reg.email,
registrant_phone_num = reg.phone,
delegate_name = delegate_name,
delegate_email = delegate_email,
# Filtering out people (with True) who couldn't participate in events because we are only interested in the people
# we had to reserve space and prepare materials for.
num_of_participants = registration.get_num_party_members(True),
special_event = registration.sibs_event,
)
registration.delete()
delete_selected.short_description = 'Delete all selected registrations'
编辑:只是尝试了delete_selected.list_display也不起作用
答案 0 :(得分:0)
您无法在函数中使用它,因此我只需要将其分页一个空格即可。
示例:
def delete_selected(modeladmin, request, queryset)
code
delete_selected.short_description = "preferred name"
谢谢。