[Django]-Django โ€“ multiplication and templates

11๐Ÿ‘

โœ…

You do need a custom template tag, but you could install django-mathfilters, which provides such basic operations:

{% load mathfilters %}

...

{{banana.price|mul:0.21}}

Taken from the mathfilters page, the included operations are:

  • sub โ€“ subtraction
  • mul โ€“ multiplication
  • div โ€“ division
  • abs โ€“ absolute value
  • mod โ€“ modulo

โ€˜Addโ€™ is provided in Django as standard.

๐Ÿ‘คStephan

1๐Ÿ‘

You can use built-in widthratio template tag:

For creating bar charts and such, this tag calculates the ratio of a
given value to a maximum value, and then applies that ratio to a
constant.

{% widthratio banana.price 100 21 %}
๐Ÿ‘คalecxe

Leave a comment