Answer the question
In order to leave comments, you need to log in
How to display category name?
There is a field that allows you to select a vehicle category.
TYPE_CHOICES = (
('leg', u"Легковое ТС"),
('gruz', u"Грузовое ТС"),
)
type = models.CharField(max_length=5, blank=True, null=True, default="m", choices=TYPE_CHOICES)
Answer the question
In order to leave comments, you need to log in
https://docs.djangoproject.com/en/2.1/ref/models/i...
No need to reinvent the wheel
Make a method or property. Something like the following:
@property
def char_type(self):
for i in TYPE_CHOICES:
if i[0] == self.type:
return i[1]
{{ model.char_type }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question