Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the model name in the django admin site?

I am translating a django app and I would like to translate also the homepage of the django admin site.

On this page are listed the application names and the model class names. I would like to translate the model class name but I don't find how to give a user-friendly name for a model class.

Does anybody know how to do that?

like image 887
luc Avatar asked Mar 17 '10 14:03

luc


People also ask

How do I change models in Django?

Create or update a model. Run ./manage.py makemigrations <app_name> Run ./manage.py migrate to migrate everything or ./manage.py migrate <app_name> to migrate an individual app.

How do I change the admin text in Django?

To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.

How do you name a Django model?

Naming Your Models The model definition is a class, so always use CapWords convention (no underscores). E.g. User , Permission , ContentType , etc. For the model's attributes use snake_case. E.g. first_name , last_name , etc.

Can we change Django admin theme?

To do so, you will have to change the project's settings.py . Find the TEMPLATES section and modify accordingly. To override the default template you first need to access the template you want to modify from the django/contrib/admin/templates/admin directory.


2 Answers

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

like image 93
Daniel Roseman Avatar answered Sep 19 '22 21:09

Daniel Roseman


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") 
like image 41
Dos Avatar answered Sep 19 '22 21:09

Dos