Get the name of the model field in the template

In the template for the presentation, I would like to use the field name, 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 {{name.get_field_name_display}}, which will result in a field name or a detailed name if one is specified; how it is done in admins and forms. Imagine using it in a template:

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

This will result in, for example:

Your name: John.
Age: 16

where "Your name" is the field with a detailed name, "Age" is the name of the field, and "John" and 16 are values.

Can someone tell me if this is possible and how it is done?

+6
django templates field model
source share
1 answer

Not easy .

0
source share

All Articles