Home >Backend Development >Python Tutorial >django模型中的字段和model名显示为中文小技巧分享

django模型中的字段和model名显示为中文小技巧分享

WBOY
WBOYOriginal
2016-06-10 15:18:581386browse

简单方法:

models.py

复制代码 代码如下:

class IceCreamBar(models.Model):
    title =

    models.CharField(max_length=200,db_index=True,verbose_name="名称")
        shell = models.CharField(max_length=100,verbose_name='外皮')
        filling = models.CharField(max_length=100,verbose_name='内含')
        has_stick = models.BooleanField(default=True,verbose_name='有没有棍')

        def __unicode__(self):
            return self.title

        class Meta:
            verbose_name = "冰棒"
            verbose_name_plural = "冰棒s"

利用国际化的翻译功能:

models

复制代码 代码如下:

from django.utils.translation import ugettext_lazy as _

class KarmaUser(AbstractUser):
karma = models.PositiveIntegerField(_("karma"),default=0,blank=True)

然后在message里面设置翻译文本即可.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn