Search code examples
djangobuttonadminadditioninline

Change the text on Django Admin's "Add another SomeObject"-button when showing inlines


With the following code, I get a Django Admin UI, where I on the Person page can add a number of Measurement's:

enter image description here

The link / button shows the text "Add another Measurement". How can I change that text?

Code:

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]

Solution

  • By adding verbose_name and verbose_name_plural to MeasurementInline, I managed to change the text (in this case to start with a lower case "m"):

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