2

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?

frbry
  • 365
  • 4
  • 23
  • I would suggest that you look into using a template filter so that you don't have massive code duplication in your templates if you use this several times. – Thomas Orozco Jun 27 '12 at 09:31

1 Answers1

14

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
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895