Add property to calculate number of days:
import datetime ... @property def days_ago(self): return (datetime.date.today() - self.gathering_date).days ...
@login_required def timeline(request): dates = DBFossilGathering.objects.filter(gathering_owner=request.user).order_by('-gathering_date') last_item = dates.last() div_height = 0 if dates: div_height = dates.last().days_ago div_large = div_height+100 return render(request, "app_fossils/timeline.html", { "dates": dates, 'div_height': div_height, "div_large": div_large, 'last_item': last_item, "nv":"timeline", })
{% extends 'base.html' %} {% block title %} Timeline {% endblock %} {% load static %} {% block content %} {% if dates %} {% for date in dates %} {% if forloop.counter|divisibleby:2 %} {{ date.gathering_date|date:'Y.m.d' }}{{ date.gathering_name|slice:28 }} {% else %} {{ date.gathering_date|date:'Y.m.d' }}{{ date.gathering_name|slice:28 }} {% endif %} {% if date == last_item %} {% endif %} {{ date.gathering_date|date:'Y.m.d' }} {{ date.gathering_name }} {% if date.gathering_description %} {{ date.gathering_description|safe }} {% endif %} {% endfor %} {% endif %} {% endblock %}