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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -