为什么 µ在django的管理中显示类似M?
我在 django 模型中使用以下代码来格式化管理界面中的列:
def formatted_mu(self):
return "%.1f%%" % self.mu
formatted_mu.short_description = u'\u03BC'
由于某种原因,它没有在标题中显示 µ,而是显示 M。我知道这应该像我尝试 u'\u03A3' I 时那样工作确实收到了Σ。
编码参考:
更新:
我发现其他小写希腊字母也与大写字母互换。有什么办法可以避免这种情况吗?
I'm using the following code in a django model to format a column in the admin interface:
def formatted_mu(self):
return "%.1f%%" % self.mu
formatted_mu.short_description = u'\u03BC'
For some reason instead of showing µ in the heading, it shows M. I know this should work as when I tried u'\u03A3' I did receive ∑.
Encoding reference:
UPDATE:
I've discovered that other lower case Greek letters are switched with their capital counterparts too. Is there any way to avoid this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那个M是大写的Mu。西格玛看起来很有特色,但大写的Mu看起来就像我们的M。
That M is a capital Mu. Sigma looks distinctive, but capital-Mu looks like our M.
Django 将任何字段的首字母大写
Django capitalizes the first letter of any field
您可以通过在 models.py 中模型定义的 Meta 类中设置
verbose_model_plural
来避免模型名称大写,并根据需要进行设置,并将空格作为第一个字符。例如,
EDIT1:我最初的解决方案不起作用,因为 django 总是将第一个字母大写,即使是在 verbose_name_plural 中(尽管它不会像管理员通常对模型名称所做的那样自动将其他字母转换为小写。)详细名称的第一个字母是空格,它可以工作。请注意,由于名称位于 html 表中(忽略第一个/最后一个字符之前的空格),因此用户不会注意到详细模型名称中的空格。
EDIT2:或者避免将字段名称大写(抱歉——没有仔细阅读问题)。
You can avoid capitalizing a model name by setting a
verbose_model_plural
in the Meta class of your model definition in models.py with the setting as you want and a space as the first character.E.g.,
EDIT1: My initial solution didn't work, as django always capitalizes the first letter even in a verbose_name_plural (though it won't automatically convert the other letters to lowercase like the admin normally does to model names.) However, making the first letter of the verbose name be a space, it works. Note since the name is in a html table (which ignores whitespace before the first/last character) the space in the verbose model name doesn't get noticed to the user.
EDIT2: Or to avoid capitalizing a field name (sorry -- didn't read question carefully).