你可以给一个Django应用程序一个详细的名称,用于整个管理员? [英] Can you give a Django app a verbose name for use throughout the admin?

查看:115
本文介绍了你可以给一个Django应用程序一个详细的名称,用于整个管理员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案可以让Django管理员中出现的字段和模板更详细的名称。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆