D
D
DUDE2020-04-23 23:59:39
Django
DUDE, 2020-04-23 23:59:39

How do list indexes work in html templates?

Hello. There is this code in one of the models:

STATUS_CASES = [
    ("A", "Available"),
    ("N", "Not availalbe")
]

status = models.CharField(max_length=1, choices=STATUS_CASES, blank=True, default="A")

If in the html template I refer to model.status, then by default a zero index is displayed in the tap. In the template, you can access the index via model.status.0 , but if I access the first element, nothing happens. How do I get the first element of the tapla? Then you have to change its maximum length. You can, of course, make ifs in a template, but is it possible to do it differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-04-24
@stympel

in the template
model.get_status_display
do you mean it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question