0

I have a couple of items (namely authentication and user_central) on the side menu of my django-admin interface which are shown in the screenshot below.

enter image description here

I want to change their text. How can I do that? I know a litle bit about overriding the template, but which blocks to override for these two menu items?

Farhat Nawaz
  • 202
  • 5
  • 20
  • 1
    Possible duplicate of [Change model class name in Django admin interface](https://stackoverflow.com/questions/8368937/change-model-class-name-in-django-admin-interface) – dabadaba Sep 14 '17 at 07:21
  • @dabadaba I don't think so. The post you have mentioned tells how to change the text of subentries, in my case these subentries come under 'user_central'. But I want to change the text of parent menu item, which is 'user_central' itself. – Farhat Nawaz Sep 14 '17 at 07:25
  • 1
    Possible duplicate of [Can you give a Django app a verbose name for use throughout the admin?](https://stackoverflow.com/questions/612372/can-you-give-a-django-app-a-verbose-name-for-use-throughout-the-admin) – user2390182 Sep 14 '17 at 07:38

1 Answers1

0

Fortunately, you don't have to tweak any template to achieve this!

In your apps, go to apps.py and add or change the AppConfig's verbose_name.

Example:

class UserCentralConfig(AppConfig):
      name = 'user_central'
      verbose_name = 'Users'

Don't forget to reference this config class in you settings.py, like this:

INSTALLED_APPS = [
  ...
  'user_central.apps.UserCentralConfig',
  ...
]
Nezo
  • 312
  • 3
  • 14
  • It gave me this error `ImportError: No module named UserCentralConfigdjango.contrib` – Farhat Nawaz Sep 14 '17 at 07:50
  • I figured it out. You were partly correct. Instead of registering it with the `INSTALLED_APPS`, we need to put it in the __init__.py file of the app, like so: `default_app_config = 'YourApp.apps.YourAppConfig' `. I'm marking your answer as 'accepted' since it led me to the solution. Thanks – Farhat Nawaz Sep 14 '17 at 07:56
  • BTW, this is fine about one of the menu items. What about the `Authentication` menu item which is not a model and comes out of the box with django-admin? Any idea? – Farhat Nawaz Sep 14 '17 at 07:59
  • `default_app_config` Is not required in any django >= 1.7, so schwobaseggl were right! – Nezo Sep 14 '17 at 08:16
  • Actually, for django >= 1.7, it IS required. For lower versions, it isn't. – Farhat Nawaz Sep 14 '17 at 08:20
  • To customize the `Authentication` verbose_name, I've had good result by overloading `AuthConfig` from `django.contrib.auth.apps`. Basically this: `class CustomAuthConfig(AuthConfig): verbose_name = 'Custom Name'` So you'll need to make a new app and reference this config in the `__init__.py` just like you did above. And you should use something like `custom_auth.apps.CustomAuthConfig` instead of `django.contrib.auth`. – Nezo Sep 14 '17 at 08:22
  • No, as stated in the [docs](https://docs.djangoproject.com/en/1.10/ref/applications/#configuring-applications): `default_app_config allows applications that predate Django 1.7 such as django.contrib.admin to opt-in to AppConfig features without requiring users to update their INSTALLED_APPS. New applications should avoid default_app_config. Instead they should require the dotted path to the appropriate AppConfig subclass to be configured explicitly in INSTALLED_APPS.` – Nezo Sep 14 '17 at 08:23
  • yeah, docs say that. But I am using django 1.8 and I had to use `default_app_config` since `INSTALLED_APPS` didn't work. – Farhat Nawaz Sep 14 '17 at 09:22
  • and that `custom_auth` method is again giving the import error I mentioned earlier. It says `ImportError: No module named CustomAuthConfigdjango.contrib` when I put it in the `INSTALLED_APPS` – Farhat Nawaz Sep 14 '17 at 09:29
  • Also, is it possible to override the default logo as well? – Farhat Nawaz Sep 14 '17 at 10:31