Answer the question
In order to leave comments, you need to log in
How to get a value from a record in a template, not a key?
I already implemented it once, but I forgot how, and I didn’t find an answer on the Internet, in short, such a problem:
there is a model:
from django.db import models
COLOR_SPISOK = (
('dc0000', 'Красный'),
('f0ef00', 'Желтый'),
)
class profilModel(models.Model):
color = models.CharField('Цвет', choices=COLOR_SPISOK, max_length=20)
class Meta:
verbose_name = 'тест'
from django.shortcuts import render
from platform_inform.models.profil import profilModel
def indexDef(request):
user = profilModel.objects.get(user_pk = request.session.get('user_pk'))
return render(request, 'site_platform_inform/index/index.html', {
# профиль
'user': user,
})
{% block main %}
<span class="text_title">{{user.color}}</span>
{% endblock main %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question