How to change app name in Django admin?

后端 未结 8 1948
小鲜肉
小鲜肉 2020-12-14 08:03

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

But for some reason I just want to change the app name in the Dj

相关标签:
8条回答
  • 2020-12-14 08:31

    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'
    
    0 讨论(0)
  • 2020-12-14 08:33

    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.
    0 讨论(0)
  • 2020-12-14 08:37

    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',
            # ...
        ]
    
    0 讨论(0)
  • 2020-12-14 08:37

    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

    0 讨论(0)
  • 2020-12-14 08:41

    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/

    0 讨论(0)
  • 2020-12-14 08:51

    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

    0 讨论(0)
提交回复
热议问题