How to change "app name" in Django admin?
Asked Answered
S

10

38

I created 'frontend' application using ./manage.py startproject frontend.

But for some reason I just want to change the app name in the Django admin to display 'Your Home Page' instead of 'frontend'.

How to do that?

Update: Here is the little more detail:

# "settings.py"

INSTALLED_APPS = (
    'frontend',
)

And:

# "frontend/models.py"

class Newpage(models.Model):
    # field here

class Oldpage(models.Model):
    #field here
Supporting answered 17/11, 2014 at 12:21 Comment(1)
possible duplicate of Can you give a Django app a verbose name for use throughout the admin?Cymose
A
61

Yes, you can do it simply

in your apps.py file from your app folder change the verbose_name attribute from your config class. For example:

from django.apps import AppConfig


class FrontendConfig(AppConfig):
    name = 'frontend'
    verbose_name = "Your Home Page"

I test it and works in Django 1.10

UPDATE:

In Django 3+ you should add this in your __init__.py file (from your app)

default_app_config = 'frontend.apps.FrontendConfig'
Aristocracy answered 14/2, 2017 at 20:56 Comment(4)
I tested it, it works fine in Django 1.11.15 (Python 2.7.15) too. Thanks.Formerly
@Jekson try to add this on your init.py from frontend app default_app_config = 'frontend'Aristocracy
@Aristocracy it should be default_app_config = "frontend.apps.FrontendConfig" or something like thatVibrio
@Vibrio yes, you're right in the newer versions of django you should add this in your init.pyAristocracy
C
18

In stars/app.py

from django.apps import AppConfig


class RequestsConfig(AppConfig):
    name = 'stars'
    verbose_name = "Star of India"

in stars/init.py

default_app_config = 'stars.apps.RequestsConfig'

To access the app name in custom menu methods you can try to get that from

model._meta.app_config.verbose_name

Check the Django Doc for reference https://docs.djangoproject.com/en/1.11/ref/applications/#for-application-users

Colvert answered 1/6, 2018 at 6:8 Comment(0)
F
8

I am late but just to add an additional step to the solution explained by @FACode.
From the offical docs:

In frontend/apps.py

from django.apps import AppConfig


class FrontendConfig(AppConfig):
    name = 'frontend'
    verbose_name = "Your Home Page"

In app/settings.py

    INSTALLED_APPS = [
        'frontend.apps.FrontendConfig',
        # ...
    ]
Faiyum answered 14/10, 2019 at 20:33 Comment(0)
R
8

apps.py

from django.apps import AppConfig

class FrontendConfig(AppConfig):
    name = 'frontend'
    verbose_name = "Your Home Page"

__ init__.py

default_app_config = 'frontend.apps.FrontendConfig'

https://docs.djangoproject.com/en/2.2/ref/applications/

Recap answered 11/11, 2019 at 6:14 Comment(2)
please provide some explanation for your content, it's unclear that this is an answer or a new question.Paddy
This is an answer for question, a writed how to change name of app, and gived link for docs.Recap
B
4

1.Try to add app_label to your model that will be registered in Admin.

class MyModel(models.Model):
        pass
    class Meta:
        app_label = 'My APP name'

UPDATE: 2. Steps to rename app(folders):

  • Rename the folder which is in your project root
  • Change any references to your app in their dependencies, i.e. the app's views, the urls.py and settings.py files.
  • 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. For renaming models, you'll need to change django_content_type.name Note: If your models.py 's Meta Class has app_name listed, make sure to rename that too.
Beira answered 17/11, 2014 at 12:56 Comment(2)
@ZenMaster Could you share you models.py?Beira
i need to change the frontend not the modelSupporting
N
4

For example, if app name is store, then add verbose_name with my store to store/apps.py as shown below:

# "store/apps.py"

from django.apps import AppConfig

class StoreConfig(AppConfig):
    name = 'store'
    verbose_name = "my store" # Here

Then, add the code below to "store/init.py":

# "store/__init__.py"

default_app_config = 'store.apps.StoreConfig'

Now, the app name store is changed to my store as shown below:

enter image description here

Nestling answered 9/8, 2022 at 22:59 Comment(0)
B
3

In apps.py

 from django.apps import AppConfig
 class AccountConfig(AppConfig):
    name = 'app name'
    verbose_name = "new app name"
Bubb answered 13/6, 2019 at 16:36 Comment(1)
Is there any information in this answer that isn't already covered by the other answers?Lebron
B
2

It sounds like you are trying to change how the appname is listed within the Django Admin? This wasn't possible before Django 1.7, but now you can do it like this:

https://docs.djangoproject.com/en/1.7/ref/applications/#for-application-users

Boulevardier answered 19/11, 2014 at 10:43 Comment(0)
H
1

In Django 2 we can use verbose_name in apps.py but we have to specify the CLass Config in init.py

See related doc here

Harts answered 29/9, 2019 at 12:12 Comment(0)
C
0

in django 3.0+ you just need to change the folder name and inside the apps.py change the "name" inside the "(appname)Config" class to the new name.

Consuelaconsuelo answered 3/2, 2021 at 0:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.