I have a Model which has some constants defined, like below:
class Order(models.Model):
WAITING = 0
APPROVED = 1
DISAPPROVED =2
I want to display some conditional tags in my template, for example, showing an hourglass icon if the displayed Order has the status of WAITING.
Currently I'm doing it like below, but I don't like it because that way, I need to keep track of values of every constants:
{% if order.status == 0 %}
your order is waiting approval.
{% endif
How can I access Order.WAITING, Order.APPROVED and Order.DISAPPROVED constants from my templates? What is the correct way of what I want to achieve?
Presumably order is an instance of Order, so it has access to the class constants already. So this would work:
if order.status == order.WAITING
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With