Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

verbose name app in django admin interface

In the Django administration Interface, we have our models grouped by app. Well, I known how to customize the model name:

class MyModel (models.Model):
  class Meta:
    verbose_name = 'My Model'
    verbose_name_plural = 'My Models'   

But I couldn't customize the app name. Is there any verbose_name for the apps ?

like image 677
Salias Avatar asked Mar 28 '13 23:03

Salias


People also ask

What is verbose name in Django?

verbose_name is a human-readable name for the field. If the verbose name isn't given, Django will automatically create it using the field's attribute name, converting underscores to spaces. This attribute in general changes the field name in admin interface.

How do I change app label in Django admin?

Edit the database table django_content_type with the following command: UPDATE django_content_type SET app_label='' WHERE app_label='' Also if you have models, you will have to rename the model tables. For postgres use ALTER TABLE _modelName RENAME TO _modelName.


2 Answers

Since django 1.7 app_label does not work. You have to follow https://docs.djangoproject.com/en/1.7/ref/applications/#for-application-authors instructions. That is:

  1. Create apps.py in your app's directory
  2. Write verbose name :

    # myapp/apps.py
    
    from django.apps import AppConfig
    
    class MyAppConfig(AppConfig):
        name = 'myapp'
        verbose_name = "Rock ’n’ roll"
    
  3. In the project's settings change INSTALLED_APPS :

    INSTALLED_APPS = [
        'myapp.apps.MyAppConfig',
        # ...
    ]
    

    Or, you can leave myapp.appsin INSTALLED_APPS and make your application load this AppConfig subclass by default as follows:

    # myapp/__init__.py
    
    default_app_config = 'myapp.apps.MyAppConfig'
    

alles :)

like image 96
igolkotek Avatar answered Sep 21 '22 00:09

igolkotek


Using the Meta class inside your model and defining the app_label there works, but most likely you will have to do that for each model in your module.

Another approach is to actually use i18n. In your po file, if you define a msgid with your app_label you should be good.

In your app, add/edit po file *app_label > locale > ru > django.po*

#set app label string 
msgid <app_label>
msgstr "Ваше приложение этикетке"

You can read more about the internationalization here and about translation here.

like image 28
goliatone Avatar answered Sep 19 '22 00:09

goliatone