I18n在Django中翻译模型

时间:2013-04-08 08:08:04

标签: django django-models internationalization django-forms translation

我有一个我要翻译的表单:

Models.py:

class Show(models.Model):
    discount_tickets = models.IntegerField("Discount Tickets")
    regular_tickets = models.IntegerField("Regular Tickets")
    afillate_price = models.IntegerField("Afillate Price")
    user_price = models.IntegerField("User Price")
    start_time = models.CharField("Event Time", max_length=20)
    sale_end_time = models.CharField("Sale End Time", max_length=20) 

    def __unicode__(self):
        return unicode(self.discount_tickets)

class ShowForm(ModelForm):
    pass

    class Meta:
        model = Show 

如何翻译字段名称?

1 个答案:

答案 0 :(得分:7)

from django.utils.translation import ugettext_lazy as _

class Show(models.Model):
    discount_tickets = models.IntegerField(_("Discount Tickets"))
    regular_tickets = models.IntegerField(_("Regular Tickets"))
    afillate_price = models.IntegerField(_("Afillate Price"))
    user_price = models.IntegerField(_("User Price"))
    start_time = models.CharField(_("Event Time"), max_length=20)
    sale_end_time = models.CharField(_("Sale End Time"), max_length=20)