您的位置:首页 > 编程语言 > Go语言

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

2016-05-24 10:01 519 查看
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_NAME
parameter.
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.

修改前



修改后:



如果修改为中文,则VERBOSE_NAME = u'中文名称',否则会执行不通过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python