From 462459964cbaa14e3c402e91452e6f134494671c Mon Sep 17 00:00:00 2001 From: Marcelino Alberdi Pereira Date: Sat, 20 Nov 2021 18:41:15 +0100 Subject: [PATCH] Add notes to child timeline --- core/timeline.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/timeline.py b/core/timeline.py index 28a82367..7bfe6196 100644 --- a/core/timeline.py +++ b/core/timeline.py @@ -3,7 +3,7 @@ from django.urls import reverse from django.utils import timezone, timesince from django.utils.translation import gettext as _ -from core.models import DiaperChange, Feeding, Sleep, TummyTime +from core.models import DiaperChange, Feeding, Note, Sleep, TummyTime from datetime import timedelta @@ -22,6 +22,7 @@ def get_objects(date, child=None): _add_feedings(min_date, max_date, events, child) _add_sleeps(min_date, max_date, events, child) _add_tummy_times(min_date, max_date, events, child) + _add_notes(min_date, max_date, events, child) events.sort(key=lambda x: x['time'], reverse=True) @@ -169,3 +170,18 @@ def _add_diaper_changes(min_date, max_date, events, child): args=[instance.id]), 'model_name': instance.model_name }) + + +def _add_notes(min_date, max_date, events, child): + instances = Note.objects.filter( + time__range=(min_date, max_date)).order_by('-time') + if child: + instances = instances.filter(child=child) + for instance in instances: + events.append({ + 'time': timezone.localtime(instance.time), + 'details': [instance.note], + 'edit_link': reverse('core:note-update', + args=[instance.id]), + 'model_name': instance.model_name + })