django mathfiters

23 views
Skip to first unread message

sum abiut

unread,
Feb 21, 2018, 5:07:58 PM2/21/18
to django...@googlegroups.com

Hi,
How to you a zero in mathfilter
for example, if the value of c is zero the total is not display. instead of displaying 42 it display nothing.

{%for b in pay%}
{% with a=42 c=b.value%}
    <li> {{ a|add:c }}</li>
    {% endwith %}

Matthew Pava

unread,
Feb 21, 2018, 5:17:49 PM2/21/18
to django...@googlegroups.com

Check the value of b.value.  Make sure it isn’t None.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y5F9bP8AVU2qXhXjMPhK4kwHBfWza2WL7j424VUkAgCRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Feb 21, 2018, 5:44:01 PM2/21/18
to django...@googlegroups.com
Thanks for your response. Yes the value was actually None. how to i display 42  instead of not displaying anything at all. I have try using the if statement to check for the value of c if its None i just display the value of a, and if is not None i add the values. But still its displaying nothing.

Thanks

On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava <Matthe...@iss.com> wrote:

Check the value of b.value.  Make sure it isn’t None.

 

From: django...@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:06 PM
To: django...@googlegroups.com
Subject: django mathfiters

 

 

Hi,

How to you a zero in mathfilter

for example, if the value of c is zero the total is not display. instead of displaying 42 it display nothing.

 

{%for b in pay%}

{% with a=42 c=b.value%}
    <li> {{ a|add:c }}</li>
    {% endwith %}

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

Matthew Pava

unread,
Feb 21, 2018, 5:49:16 PM2/21/18
to django...@googlegroups.com

And how are you checking if it’s None?  I would do it like this:

{% if c %}

    {{ a|add:c }}

{% else %}

  {{ a }}

{% endif %}

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:43 PM
To: django...@googlegroups.com
Subject: Re: django mathfiters

 

Thanks for your response. Yes the value was actually None. how to i display 42  instead of not displaying anything at all. I have try using the if statement to check for the value of c if its None i just display the value of a, and if is not None i add the values. But still its displaying nothing.

 

Thanks

On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava <Matthe...@iss.com> wrote:

Check the value of b.value.  Make sure it isn’t None.

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of sum abiut
Sent: Wednesday, February 21, 2018 4:06 PM
To: django...@googlegroups.com
Subject: django mathfiters

 

 

Hi,

How to you a zero in mathfilter

for example, if the value of c is zero the total is not display. instead of displaying 42 it display nothing.

 

{%for b in pay%}

{% with a=42 c=b.value%}
    <li> {{ a|add:c }}</li>
    {% endwith %}

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.




--

--

You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

sum abiut

unread,
Feb 21, 2018, 8:18:15 PM2/21/18
to django...@googlegroups.com
Thanks heaps.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.




--

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

Peter of the Norse

unread,
Feb 28, 2018, 1:06:57 AM2/28/18
to django...@googlegroups.com
I would do
{% with a=42 c=b.value|default_if_none:0}

- Peter of the Norse

sum abiut

unread,
Feb 28, 2018, 4:31:07 AM2/28/18
to django...@googlegroups.com
Thanks Peter.

cheers,

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages