如何在Django Admin中设置其他内联标题?

时间:2023-01-14 19:36:32

I need to change the inline title (name) to something other than the verbose_name of the class Meta in the Model. Is there a variable to do this?

我需要将内联标题(名称)更改为模型中元类的verbose_name以外的内容。有一个变量来做这个吗?

1 个解决方案

#1


48  

As documented, you need to set the values of your InlineModelAdmin subclass:

如文件所示,您需要设置InlineModelAdmin子类的值:

InlineModelAdmin.verbose_name - An override to the verbose_name found in the model’s inner Meta class.

InlineModelAdmin。verbose_name——在模型的内部元类中找到的对verbose_name的重写。

InlineModelAdmin.verbose_name_plural - An override to the verbose_name_plural found in the model’s inner Meta class.

InlineModelAdmin。verbose_name_复数-在模型的内元类中找到了verbose_name_复数的覆盖。

In this example, instead of the title 'Device' we use 'Phone':

在本例中,我们使用的不是标题“设备”,而是“电话”:

class DeviceInline(admin.TabularInline):
    model = Device
    verbose_name = "Phone"
    verbose_name_plural = "My Phones"

#1


48  

As documented, you need to set the values of your InlineModelAdmin subclass:

如文件所示,您需要设置InlineModelAdmin子类的值:

InlineModelAdmin.verbose_name - An override to the verbose_name found in the model’s inner Meta class.

InlineModelAdmin。verbose_name——在模型的内部元类中找到的对verbose_name的重写。

InlineModelAdmin.verbose_name_plural - An override to the verbose_name_plural found in the model’s inner Meta class.

InlineModelAdmin。verbose_name_复数-在模型的内元类中找到了verbose_name_复数的覆盖。

In this example, instead of the title 'Device' we use 'Phone':

在本例中,我们使用的不是标题“设备”,而是“电话”:

class DeviceInline(admin.TabularInline):
    model = Device
    verbose_name = "Phone"
    verbose_name_plural = "My Phones"