gpt4 book ai didi

django - 显示内联时更改 Django Admin 的 "Add another SomeObject"- 按钮上的文本

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

使用以下代码,我得到了一个 Django 管理 UI,我可以在 Person 页面上添加一些 Measurement:

enter image description here

链接/按钮显示文本“添加另一个测量”。我该如何更改该文本?

代码:

class Person(models.Model):
class Meta:
db_table = 'people'
verbose_name = "Person"
verbose_name_plural = "People"

name = models.CharField(max_length=100, null=False, blank=False)


class Measurement(models.Model):
class Meta:
db_table = 'measurements'
verbose_name = "Measurement"
verbose_name_plural = "Measurements"

value = models.IntegerField(null=False)
person = models.ForeignKey(Person, null=False, on_delete=CASCADE)


class MeasurementInline(InlineModelAdmin):
model = Measurement
extra = 0


class PersonAdmin(admin.ModelAdmin):
fields = ('name',)
list_display = ('name',)

inlines = [MeasurementInline]

最佳答案

通过将 verbose_nameverbose_name_plural 添加到 MeasurementInline,我设法更改了文本(在本例中以小写字母“m”开头"):

class MeasurementInline(InlineModelAdmin):
model = Measurement
extra = 0
verbose_name = 'measurement'
verbose_name_plural = 'measurements'

关于django - 显示内联时更改 Django Admin 的 "Add another SomeObject"- 按钮上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64045112/

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