views:

30

answers:

2

Hi,

in a Model I have a CharField with choices:

class MyModel(models.Model):
    THE_CHOICES=(
        ('val',_(u'Value Description')),
    )
    ...
    myfield=models.CharField(max_length=3,choices=THE_CHOICES

Now in the template I access an instance of MyModel: {{ my_instance.myfield }} Of course the gives me val instead of Value Description. How do I get the description?

Thanks in advance!

+3  A: 

You need to use {{ my_instance.get_myfield_display }}, as documented here: http://docs.djangoproject.com/en/1.1/ref/models/instances/#django.db.models.Model.get_FOO_display

Alex Gaynor
thanks alex, how could I miss that?
Till Backhaus
A: 

{{ my_instance.get_myfield_display }}

winner, exactly what I needed, thanks.

datakid