Can anyone tell me if its possible to send multiple variables from field names to a template tag?
this question How do I add multiple arguments to my custom template filter in a django template? is almost there, but i dont know how to send my two field names as a string.
my template:
<th>{{ item.cost_per_month|remaining_cost:item.install_date + ',' + item.contract_length }}</th>
the above didnt work
my template tags:
@register.filter('contract_remainder')
def contract_remainder(install_date, contract_term):
months = 0
now = datetime.now().date()
end_date = install_date + relativedelta(years=contract_term)
while True:
mdays = monthrange(now.year, now.month)[1]
now += timedelta(days=mdays)
if now <= end_date:
months += 1
else:
break
return months
@register.filter('remaining_cost')
def remaining_cost(cost_per_month, remainder_vars):
dates = remainder_vars.split(',')
cost = contract_remainder(dates[0], dates[1]) * cost_per_month
return cost
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…