T
T
tarp202020-07-28 15:34:39
Django
tarp20, 2020-07-28 15:34:39

How to fix output in Django?

how to make the status output not a number but a string
src=" https://habrastorage.org/webt/5f/20/1a/5f201ae92dd... " alt="image"/>

models.py

class Order(models.Model):
    COOCKING = 1
    READY = 2
    ONTHEWAY = 3
    DELIVERED = 4

    STATUS_CHOICES = (
        (COOCKING,"COOCKING"),
        (READY, "READY"),
        (ONTHEWAY, "ON THE WAY"),
        (DELIVERED, "DELIVERED"),
    )
        status = models.IntegerField( choices = STATUS_CHOICES)


html template i.e. instead of 2 output "READY"

<td>{{ order.status}}</td>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-07-28
@bacon

https://docs.djangoproject.com/en/3.0/ref/models/i...

E
Eugene D., 2020-07-29
@devg

Use the "magic" method field_name_display() when getting the value :
<td>{{ order.status_display()}}</td>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question