开发者

mark lables for translation in Django Forms

Let's say I have this form:

class RSVPForm(forms.Form):
  attending_dinner= forms.ChoiceField(_('attending_dinner'), c开发者_开发问答hoices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
  attending_brunch = forms.ChoiceField(choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
  number_of_guests = forms.IntegerField(initial=0)

How can I mark the fields' names ex. attending_dinner for translation ?


here is the answer:

from django.utils.translation import ugettext, ugettext_lazy as _

class RSVPForm(forms.Form):
attending_dinner= forms.ChoiceField(label=_('attending_dinner'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
attending_brunch = forms.ChoiceField(label=_('attending_brunch'), choices=VISIBLE_ATTENDING_CHOICES, initial='yes', widget=forms.RadioSelect)
number_of_guests = forms.IntegerField(initial=0)
comment = forms.CharField(max_length=255, required=False, widget=forms.Textarea)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜