Django DecimalField returns "None" instead of empty value
Posted
by Ed
on Stack Overflow
See other posts from Stack Overflow
or by Ed
Published on 2010-03-26T16:21:18Z
Indexed on
2010/03/26
16:23 UTC
Read the original article
Hit count: 352
Is there a way to force django to display nothing instead of "None" for a Decimal Field that's been left blank?
In my template, I show a list of all the values for a particular field. Each value is hyperlinked to a page that displays the results of a query filtered on that value. But because there are some entries with null value, my list includes actual DecimalField entries and "None" for all those that are empty. When a user clicks on None, django throws a validation error because you cannot query a DecimalField using a string.
I could write if statements checking all instances of decimal fields for Nones and skipping them, but that is far from an elegant solution. Any advice?
This is one part of the code, though there are other templates that derive the None value in slightly different manners:
{% for item in choices %}
<a href={% url app_views.field_choice item %}>{{ item }}</a><br>
{% endfor %}
© Stack Overflow or respective owner