如何在django中停止verbose_name的自动大写 [英] How to stop auto-capitalization of verbose_name in django

查看:182
本文介绍了如何在django中停止verbose_name的自动大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止Django在模型中自动使用verbose_name大写?例如:

How to prevent Django from auto-capitalizing of the verbose_name in models? E.g:

class TestModel(models.Model):
    enb_id = models.IntegerField(null=True, verbose_name="eNB ID", blank=True)

我想自己处理大小写并显示 而不是网站上的ENB ID。

I want to handle the capitalization myself and display "eNB ID" instead of "ENB ID" anywhere on the site.

推荐答案

似乎简单的解决方法是添加一个空格开始 verbose_name 。执行大小写的功能( capfirst )只会更改第一个字母。如果是空白的话,什么都不会改变。因为Web浏览器忽略连续的空格,所有内容都将被正确显示。

It seems like the simple workaround for this is adding a whitespace at the beginning of verbose_name. Function that performs the capitalization (capfirst) changes only the first letter. If it is a whitespace nothing will be changed. Because web browsers ignore consecutive whitespaces everything will be displayed correctly.

class TestModel(models.Model):
    enb_id = models.IntegerField(null=True, verbose_name=" eNB ID", blank=True)

    class Meta:
        verbose_name = " test model"

这篇关于如何在django中停止verbose_name的自动大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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