rabbid
rabbid

Reputation: 5725

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 selection 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!

Upvotes: 0

Views: 521

Answers (1)

Sam Dolan
Sam Dolan

Reputation: 32532

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

Upvotes: 2

Related Questions