I’m trying to display the verbose_name (or the default name when no verbose_name exists), in the “detail” display of a model.
I’ve tried something like this, but it doesn’t work:
{{ client.funky_field_1.verbose_name }}
models.py
class Client(models.Model):
funky_field_1 = models.CharField("Daily living", max_length=20, default='')
funky_field_2 = models.CharField(max_length=20, default='')
views.py
class ClientDetail(UserAccessMixin, generic.DetailView):
model = Client
template_name = 'clients/client_detail.html'
def get_context_data(self, **kwargs):
context = super(ClientDetail, self).get_context_data(**kwargs)
context['client'] = self.object
return context
client_detail.html
<div class="row mb-1">
<div class="col-sm-3 fLabel">{{ client.funky_field_1.verbose_name }}:</div>
<div class="col-sm-9">{{ client.funky_field_1 }}</div>
</div>
<div class="row mb-1">
<div class="col-sm-3 fLabel">{{ client.funky_field_2.verbose_name }}:</div>
<div class="col-sm-9">{{ client.funky_field_2 }}</div>
</div>
Any idea on how to programmatically make the verbose_name appear, without having to write it out for every field when displaying the info in a detail page?