1

It's the classic way to describe Modules in Django Admin, and it works great!

at bookshelf/apps.py

from django.apps import AppConfig
class BOOKConfig(AppConfig):
    name = 'bookshelf'
    verbose_name = "Your Book"

at bookshelf/__init__.py:

default_app_config = 'bookshelf.apps.BOOKConfig'

BUT when you want to override titles of external modules (e.g. like packages from https://djangopackages.org/), what's the right way to override the default name at this sections and the items inside that?

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Fernando Cesar
  • 131
  • 2
  • 6

3 Answers3

1

As the docs say, new applications should avoid default_app_config.

Instead of adding default_app_config to the app's __init__.py, just use the dotted path to the app config in INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'bookshelf.apps.BOOKConfig'
    ...
]

For a third-party app you can do the same thing. Create an apps.py somewhere in your project (e.g alongside myproject/settings.py), and create an app config.

from third_party_app..apps import ThirdPartyConfig

class MyThirdPartyConfig(ThirdPartyConfig):
    verbose_name = "Customized app name"

If the app doesn't have an App Config class, then subclass AppConfig and make sure you set name.

from django.apps import AppConfig
class MyThirdPartyConfig(AppConfig):
    name = 'third_party_app'
    verbose_name = "Customized app name"

Then use the path to your app config class in INSTALLED_APPS instead of the app name/default app config.

INSTALLED_APPS = [
    ...
    'myproject.apps.MyThirdPartyConfig,
    ...
]

See the for application users section of the docs for another example.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • **It's works perfectly! Fantastic! Thank you so much Alasdair.** One more thing(if anyone will try this too) at the bellow list we need to **remove origial app name to detriment of the new config** even perhaps add variable name to the new config like Alasdair said :D Greattttttt. INSTALLED_APPS = [ ... 'bookshelf.apps.BOOKConfig' ... ] – Fernando Cesar Mar 01 '19 at 18:42
0

Suppose you have a model like this:

class Stuff(models.Model):
    class Meta:
        verbose_name = u'The stuff'
        verbose_name_plural = u'The bunch of stuff'

You have verbose_name, however you want to customise app_label too for different display in admin. Unfortunatelly having some arbitrary string (with spaces) doesn't work and it's not for display anyway.

Turns out that the admin uses app_label. title () for display so we can make a little hack: str subclass with overriden title method:

class string_with_title(str):
    def __new__(cls, value, title):
        instance = str.__new__(cls, value)
        instance._title = title
        return instance

    def title(self):
        return self._title

    __copy__ = lambda self: self
    __deepcopy__ = lambda self, memodict: self

Now we can have the model like this:

class Stuff(models.Model):
    class Meta:
        app_label = string_with_title("stuffapp", "The stuff box")
        # 'stuffapp' is the name of the django app
        verbose_name = 'The stuff'
        verbose_name_plural = 'The bunch of stuff'

Original Ionel's post https://blog.ionelmc.ro/2011/06/24/custom-app-names-in-the-django-admin/

Fernando Cesar
  • 131
  • 2
  • 6
0

Stumbled upon this while looking for a way to rename external Django installed apps / packages in my Django admin interface. I'm using Django 3.2.16. And the below is how I get it done.

In any of the apps.py of an included app using the external installed app, import the package apps.

from <package-name>.apps import <package-name>Config

Then, extend the verbose_name property.

<package-name>Config.verbose_name = '<custom-name-here>'

Hope this helps anyone coming over stumbling upon this question!