gpt4 book ai didi

django - Django中模型形式的I18n翻译

转载 作者:行者123 更新时间:2023-12-04 23:24:18 25 4
gpt4 key购买 nike

我有一个表格要翻译:

模型.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

如何翻译字段名称?

最佳答案

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)

关于django - Django中模型形式的I18n翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15874188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com