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)
精彩评论