gpt4 book ai didi

python - 如何更改名称/标签以删除 Django 管理中更改列表页面中的对象

转载 作者:行者123 更新时间:2023-12-05 06:18:05 25 4
gpt4 key购买 nike

我正在使用 Django,我想更改 Django 管理中更改列表页面中显示删除操作的名称/标签,如图所示:

enter image description here

我的 admin.py 文件如下所示:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin


from .models import CustomUser


class CustomUserAdmin(UserAdmin):

change_list_template='change_list_form.html'

change_form_template = 'change_form.html'

add_form_template='add_form.html'

list_display = ('first_name','last_name','email','is_staff', 'is_active',)
list_filter = ('first_name','email', 'is_staff', 'is_active',)

search_fields = ('email','first_name','last_name','a1','a2','city','state','pincode')
ordering = ('first_name',)

add_fieldsets = (
('Personal Information', {
# To create a section with name 'Personal Information' with mentioned fields
'description': "",
'classes': ('wide',), # To make char fields and text fields of a specific size
'fields': (('first_name','last_name'),'email','a1','a2','city','state','pincode','check',
'password1', 'password2',)}
),
('Permissions',{
'description': "",
'classes': ('wide', 'collapse'),
'fields':( 'is_staff', 'is_active','date_joined')}),
)

那么有什么方法可以改变它或者它是永久性的吗??

提前致谢!

最佳答案

是的,它可以改变。

然后将以下代码添加到您的 admin.py 文件中:

from django.contrib.admin.actions import delete_selected

delete_selected.short_description = 'Type here your new name/label for the delete action'

添加此 admin.py 文件后,您的 admin.py 文件应如下所示:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin


from .models import CustomUser


from django.contrib.admin.actions import delete_selected

delete_selected.short_description = 'Type here your new name/label for the delete action'


class CustomUserAdmin(UserAdmin):

change_list_template='change_list_form.html'

change_form_template = 'change_form.html'

add_form_template='add_form.html'

list_display = ('first_name','last_name','email','is_staff', 'is_active',)
list_filter = ('first_name','email', 'is_staff', 'is_active',)

search_fields = ('email','first_name','last_name','a1','a2','city','state','pincode')
ordering = ('first_name',)

add_fieldsets = (
('Personal Information', {
# To create a section with name 'Personal Information' with mentioned fields
'description': "",
'classes': ('wide',), # To make char fields and text fields of a specific size
'fields': (('first_name','last_name'),'email','a1','a2','city','state','pincode','check',
'password1', 'password2',)}
),
('Permissions',{
'description': "",
'classes': ('wide', 'collapse'),
'fields':( 'is_staff', 'is_active','date_joined')}),
)

这就是您所要做的。

关于python - 如何更改名称/标签以删除 Django 管理中更改列表页面中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61401541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com