开发者

django translation(?) in templates

I put a (?) after translation because I'm not sure if this is a translation issue or not.

I have a UserProfile model that looks like so:

class UserProfile(models.Model) :
GENDER_CHOICES = (('M', _('Male')),
                  ('F', _('Female')))
gender = models.CharField(max_length=2, choices=GENDER_CHOICES, blank=True, null=True)
user = models.ForeignKey(User, unique=True)

as well as a corresponding UserProfileModelForm. When I display said form using form.as_p the Gender field is shown as a drop-down select开发者_StackOverflow社区ion and it displays "Male" and "Female."

Now I want to show the same words in my Profile Detail template, but when I do {{ profile.gender }} the letters "M" and "F" are displayed. This is as expected of course, because that is what's recorded in the database. But how do I make my Profile Detail template show "Male" and "Female" as well?

Thanks!


You can do {{ profile.get_gender_display }} See the docs here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜