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
- [Django]-I can't insert a footnote into the copied text
- [Django]-Why is django.test.client.Client not keeping me logged in
- [Django]-How do I retrieve a value of a field in a queryset object
- [Django]-Django: ValidationError using is_authenticated and logout when authenticating from an external source
- [Django]-How do I treat django's TemporaryUploadedFile as a regular python file
Source:stackexchange.com