[Django]-How to translate a model label in Django Admin?

73👍

Look at the Meta options verbose_name and verbose_name_plural, both of which are translatable.

21👍

You should use the ugettext_lazy util in the Meta of all your models

from django.db import models
from django.utils.translation import ugettext_lazy as _

class Book(models.Model):
    ...

    class Meta:
        verbose_name = _("My Book")
        verbose_name_plural = _("My Books")
👤Dos

1👍

You should use gettext_lazy() and set it to verbose_name and verbose_name_plural to translate a model label in Django Admin as shown below. *You can see my answer explaining how to translate in Django in detail:

# "models.py"

from django.db import models
from django.utils.translation import gettext_lazy as _

class Person(models.Model):
    ...

    class Meta:
        verbose_name = _("person") # Here
        verbose_name_plural = _("persons") # Here

0👍

also you can override admin.ModelAdmin to customize model name in admin only, without changing Model meta

def __init__(self, model: type, admin_site: AdminSite) -> None:
        super().__init__(model, admin_site)
        self.opts.verbose_name = 'your custom model name'
        self.opts.verbose_name_plural = 'your custom title plural'

Leave a comment