Use a timedelta for last tummy time card.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-20 11:45:26 -04:00
parent f81f763cfb
commit 591f2fba52
2 changed files with 6 additions and 4 deletions

View File

@ -1,9 +1,10 @@
{% extends 'cards/tummytime.html' %} {% extends 'cards/tummytime.html' %}
{% load duration %}
{% block header %}Today's Tummy Time{% endblock %} {% block header %}Today's Tummy Time{% endblock %}
{% block title %} {% block title %}
<strong>{{ stats.total }}</strong> seconds <strong>{{ stats.total|duration_string }}</strong>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -13,7 +14,7 @@
{% block listgroup %} {% block listgroup %}
<ul class="list-group list-group-flush text-muted small"> <ul class="list-group list-group-flush text-muted small">
{% for instance in instances %} {% for instance in instances %}
<li class="list-group-item">{{ instance.duration }} at {{ instance.end|time }}</li> <li class="list-group-item">{{ instance.duration|duration_string }} at {{ instance.end|time }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from collections import OrderedDict from collections import OrderedDict
from datetime import timedelta
from django import template from django import template
from django.utils import timezone from django.utils import timezone
@ -59,9 +60,9 @@ def card_tummytime_last(child):
def card_tummytime_day(child, date=timezone.now().date()): def card_tummytime_day(child, date=timezone.now().date()):
instances = TummyTime.objects.filter( instances = TummyTime.objects.filter(
child=child, end__day=date.day).order_by('-end') child=child, end__day=date.day).order_by('-end')
stats = {'total': 0, 'count': instances.count()} stats = {'total': timedelta(seconds=0), 'count': instances.count()}
for instance in instances: for instance in instances:
stats['total'] += instance.duration_td().seconds stats['total'] += timedelta(seconds=instance.duration_td().seconds)
return {'stats': stats, 'instances': instances, 'last': instances.first()} return {'stats': stats, 'instances': instances, 'last': instances.first()}