0👍
I would really advise that you retain separation of logic and display of information. The Django template system is purposely designed to minimize your ability to shoot yourself in the foot by gumming up your templates with logic and calculations.
Perform your calculations and logical manipulation in the view, and pass the finished product to the template. The template language is there to help you maintain code reusability and “debuggability” by attempting to enforce this separation of responsibility.
1👍
You can have nested tags:
{% for foo in bar %}
{% for zoo in foo %}
{% endfor %}
{% endfor %}
To add something, you need the add
template filter.
{{ player.score|add:subtotal }}
However, your problem needs to be resolved in the view. Since even with custom tags you cannot reliably keep track of a running total of a single variable in the template.
See this answer for an implementation to get you started, but note that they are talking about summing a list.
This kind of logic should be done in the view.
- [Answer]-How to make 'dirent of' in where clause of a query?
- [Answer]-Django Celery Start
- [Answer]-Django-Haystack – How to sort using get parameters?
- [Answer]-Django AutoSlugField across inherited models