你可以给一个Django应用程序一个详细的名称,用于整个管理员? [英] Can you give a Django app a verbose name for use throughout the admin?
问题描述
Django 1.7之前
您可以通过在模型定义中定义app_label来为应用程序提供自定义名称。但是,由于django构建了管理页面,它将通过其app_label对模型进行散列,所以如果您希望它们出现在一个应用程序中,则必须在应用程序的所有模型中定义此名称。
class MyModel(models.Model):
pass
class Meta:
app_label ='我的APP名称'
Django 1.7 +
通过rhunwicks对OP的评论,现在可以从Django 1.7开始即可开始。
从 docs :
#在yourapp / apps.py
from django.apps import AppConfig
class YourAppConfig(AppConfig):
name ='yourapp'
verbose_name ='花式标题'
然后将 default_app_config
变量为 YourAppConfig
#在yourapp / __ init__.py
default_app_config ='yourapp.apps.YourAppConfig'
In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name?
Prior to Django 1.7
You can give your application a custom name by defining app_label in your model definition. But as django builds the admin page it will hash models by their app_label, so if you want them to appear in one application, you have to define this name in all models of your application.
class MyModel(models.Model):
pass
class Meta:
app_label = 'My APP name'
Django 1.7+
As stated by rhunwicks' comment to OP, this is now possible out of the box since Django 1.7
Taken from the docs:
# in yourapp/apps.py
from django.apps import AppConfig
class YourAppConfig(AppConfig):
name = 'yourapp'
verbose_name = 'Fancy Title'
then set the default_app_config
variable to YourAppConfig
# in yourapp/__init__.py
default_app_config = 'yourapp.apps.YourAppConfig'
这篇关于你可以给一个Django应用程序一个详细的名称,用于整个管理员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!