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.
修改前
修改后
如果修改為中文顿天,則VERBOSE_NAME = u'中文名稱(chēng)'堂氯,否則會(huì)執(zhí)行不通過(guò)。