My django project it's about money management, so one of it's type of money transaction is MultipleTransaction, it only says that it was made by multiple users together.
I want to show in my interface the total value from one MultipleTransaction, using the Django template engine, how do I do that?
I tried the following:
template.html
{% with total=transaction.value*transaction.users.count %}
R${{ total }}
{% endwith %}
But I get this error message:
TemplateSyntaxError at /historico/
Could not parse the remainder: '*transaction.users.count' from 'transaction.value*transaction.users.count'
Model.py
# An abstract class containing info about a Transaction made by multiple users
class MultipleTransaction (Info):
# All users that paid the the monthly bill
users = models.ManyToManyField(User)
#A file as receipt, it can be an image or a pdf. This is optional
receipt = models.FileField(
'Comprovante(s)',
upload_to='comprovantes',
blank=True,
null=True
)
class Meta:
# Make this class an Abstract class
abstract = True
# Human friendly singular and plural name
verbose_name = 'Transação em Grupo'
verbose_name_plural = 'Transações em Grupo'
View.py
@login_required
def historico(request):
# Those 3 lines are queries of all transactions
deposits = chain(Deposit.objects.all(), MonthlyDeposit.objects.all())
withdraws = chain(Withdraw.objects.all(), EventSubscription.objects.all())
transferences = Transference.objects.all()
# Then all transactions are sorted by their atribute "created_at"
transactions = sorted(
chain(deposits,withdraws,transferences),
key=lambda instance: instance.created_at
)
# Get all boxes to show their values
boxes = Box.objects.all()
return render(
request,
'shell/app_shell.html',
{
'is_varys': True,
'transactions': transactions,
'boxes':boxes,
'title': 'Histórico'
}
)