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
- [Django]-Django: How to get related objects of a queryset?
- [Django]-">", "<", ">=" and "<=" don't work with "filter()" in Django
- [Django]-Strings won't be translated in Django using format function available in Python 2.7
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
- [Django]-Serving dynamically generated ZIP archives in Django
- [Django]-How to dynamically compose an OR query filter in Django?
- [Django]-Django Test Client Method Override Header
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'
- [Django]-Django Test Client Method Override Header
- [Django]-Case insensitive unique model fields in Django?
- [Django]-Feedback on using Google App Engine?
Source:stackexchange.com