美文网首页
修改django.admin中一个应用的名称

修改django.admin中一个应用的名称

作者: jova_y | 来源:发表于2017-11-22 17:52 被阅读0次

The following plug-and-play piece of code works perfectly since Django 1.7. All you have to do is copy the below code in the init.py file of the specific app and change the VERBOSE_APP_NAMEparameter.

#-*- coding=utf-8 -*-
from os import path
from django.apps import AppConfig

VERBOSE_APP_NAME = "YOUR VERBOSE APP NAME HERE"


def get_current_app_name(file):
    return path.dirname(file).replace('\\', '/').split('/')[-1]


class AppVerboseNameConfig(AppConfig):
    name = get_current_app_name(__file__)
    verbose_name = VERBOSE_APP_NAME


default_app_config = get_current_app_name(__file__) + '.__init__.AppVerboseNameConfig'

If you use this for multiple apps, you should factor out the get_current_app_name function to a helper file.

修改前

修改前.png
修改后
修改后.png
如果修改为中文,则VERBOSE_NAME = u'中文名称',否则会执行不通过。

相关文章

网友评论

      本文标题:修改django.admin中一个应用的名称

      本文链接:https://www.haomeiwen.com/subject/mjalvxtx.html