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