0

I write in my template: {% if ticket_price.discounted_price %}. Now that works perfect, until ticket_price.discounted_price = 0. As 0 can happen (original price = 10, discount = 10 > discounted_price = 0) if want to include this option.

However, it seems if ticket_price.discounted_price 'thinks' 0 is equal to None. How would you solve that?

Joey Coder
  • 3,199
  • 8
  • 28
  • 60

2 Answers2

2

You can check explicitly for None {% if ticket_price.discounted_price is None %} see this post for more details not None test in Python

Hotpepper
  • 256
  • 1
  • 9
1

"if" tests for truthiness in Python. If you want to explicitly check for None:

{% if ticket_price.discounted_price == None %}

See also: What is the equivalent of "none" in django templates?

WinterMute
  • 519
  • 3
  • 9