views:

31

answers:

1

In a template for a view I would like to use the name of a field and not just the value. So for example if I have this:

class Test(models.Model):
 name = models.CharField(max_length=2, verbose_name = 'Your name')
 age = models.PositiveSmallIntegerField(max_length=3)

I would like to be able to do {{ name.get_field_name_display }} which will result in either the field's name or the verbose name if it is specified; like the way it is done in the admin and forms. Imagine using it like this in the template:

{{name.get_field_name_display}}: {{name}}.
{{age.get_field_name_display}}: {{age}}.

Which would result in, for example:

Your name: John.
Age: 16.

where 'Your name' is the field verbose name, 'Age' is the field name and 'John' and 16 are the values.

Could anyone tell me if this is possible and how it is done?

+1  A: 

Not easily.

Ignacio Vazquez-Abrams