让django模型中的字段和model名显示为中文

简单方法:

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里面设置翻译文本即可.

    原文作者:walterrwu
    原文地址: https://segmentfault.com/a/1190000000756480
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞