显示内联时更改 Django Admin 的 "Add another SomeObject" 按钮上的文本
Change the text on Django Admin's "Add another SomeObject"-button when showing inlines
使用以下代码,我得到了一个 Django Admin UI,我可以在 Person 页面上添加一些 Measurement:
link / 按钮显示文本“添加另一个测量”。我该如何更改该文本?
代码:
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_name
和 verbose_name_plural
添加到 MeasurementInline
,我设法更改了文本(在本例中以小写“m”开头):
class MeasurementInline(InlineModelAdmin):
model = Measurement
extra = 0
verbose_name = 'measurement'
verbose_name_plural = 'measurements'
使用以下代码,我得到了一个 Django Admin UI,我可以在 Person 页面上添加一些 Measurement:
link / 按钮显示文本“添加另一个测量”。我该如何更改该文本?
代码:
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_name
和 verbose_name_plural
添加到 MeasurementInline
,我设法更改了文本(在本例中以小写“m”开头):
class MeasurementInline(InlineModelAdmin):
model = Measurement
extra = 0
verbose_name = 'measurement'
verbose_name_plural = 'measurements'