handling nulls and zero values in django -
if have model nullable field:
class something(models.model): parameter = models.floatfield(blank=true,null=true)
i want handle in view or template.
if something.parameter has value, want return value, , if null, want return 'n/a'.
if use:
something = something.objects.get(id=1) output_string = 'parameter value: %s' % (something.parameter or 'n/a')
then works, except in case something.parameter=0, returns 'n/a' rather desired '0'.
how can correct behaviour?
is there way of doing directly in template?
use default_if_none
template filter:
{{ value|default_if_none:"n/a" }}
Comments
Post a Comment