For posterity: this is what I used at the end. This is the contents of <app>/templatetags/datetime_filter.py
:
# -*- coding: utf-8 -*- """Application filter for `datetime`_ 24 hours. .. _datetime: https://docs.python.org/2/library/datetime.html """ from django import template from datetime import date, timedelta register = template.Library() @register.filter(name='format_datetime') def format_datetime(value): hours, rem = divmod(value.seconds, 3600) minutes, seconds = divmod(rem, 60) return '{}h {}m'.format(hours, minutes)
Then in the view add the following:
{% load datetime_filter %} [...] {{ slice.day0|format_datetime }}
source share