如何在Django admin中更改更改列表页中删除对象的namelabel。

我在Django上工作,我想改变Django管理中更改列表页中删除操作出现的namelabel,如图所示。

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')}),
    )

这就是你要做的一切。

给TA打赏
共{{data.count}}人
人已打赏
未分类

如何避免函数中参数过多。C++

2022-9-8 15:46:23

未分类

道具在vue js中被突变了。

2022-9-8 15:46:25

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索