Wednesday, December 18, 2019

Re: Can I perform calculations directly in django tags/filters?

you should indicate which files codes should be added to

On Tuesday, November 18, 2008 at 11:21:09 PM UTC+1, Daniel Roseman wrote:
On Nov 18, 7:55 pm, jago <java.j...@gmail.com> wrote:
> I am thinking about something like {{  (width - 5) *12  }}  ?

No. You can add or subtract using the 'add' filter:
{{ width:add:"-5" }}
but anything else will require a custom template tag or filter.
Luckily, these are extremely easy to write:

@register.filter
def multiply(value, arg}
    return int(value) * int(arg)

{{ width|multiply:12 }}

You'll want to add error checking and so on of course, but that's the
idea.

--
DR.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b901f38-024c-47b6-9794-c116b6d9913c%40googlegroups.com.

No comments:

Post a Comment