So, I have a decimalfield that can be 3 different values. In my view, I pass in a dictionary of values that contains the appropriate decimal values as keys.
{% for item in booklist %} {% for key, value in numvec.items %} {{item.number}} {% ifequals item.number {{key}} %} {{value}} {% endifequals %} {% endfor %} {% endfor %}
this is the dict I pass in as numvec:
numvec = {'TEST':Decimal('0.999'), 'TEST2':Decimal('0.500'),
‘TEST3’:Decimal(‘0.255’)}
the number field was defined as having these choices in my model:
BOOK_CHOICES=((Decimal('0.999'), 'TEST'),(Decimal('0.500'), 'TEST2'),(Decimal('0.255'), 'TEST3'),)
The item number prints out just fine in the view if I compare the dict with the attribute, but for some reason the ifequals cannot properly compare two decimals together. Is this a bug, or am I doing something wrong in my template with ifequals?
According to this, it seems you can only compare strings. I’d make my own template tag if I were you.